CodeForces-17A-Noldbach problem

原创 2016年05月31日 22:24:07

Description

Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even integer greater than 2 can be expressed as the sum of two primes. That got Nick’s attention and he decided to invent a problem of his own and call it Noldbach problem. Since Nick is interested only in prime numbers, Noldbach problem states that at least k prime numbers from 2 to n inclusively can be expressed as the sum of three integer numbers: two neighboring prime numbers and 1. For example, 19 = 7 + 11 + 1, or 13 = 5 + 7 + 1.

Two prime numbers are called neighboring if there are no other prime numbers between them.

You are to help Nick, and find out if he is right or wrong.

Input

The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).

Output

Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.

Sample Input
Input

27 2

Output

YES

Input

45 7

Output

NO

Hint

In the first sample the answer is YES since at least two numbers can be expressed as it was described (for example, 13 and 19). In the second sample the answer is NO since it is impossible to express 7 prime numbers from 2 to 45 in the desired form.

直接打个素数表就然后找就OK了,数据范围不大

#include<bits/stdc++.h>
 using namespace std;
 const int N = 2222;
 int prime[N],pre[N];

 bool pri(int num)
 {
    for(int i=2;i*i<=num;i++)
      if(num%i==0) return false;
    return true;
 }


 void init()
 {
    int i,j,cnt;
    for(i=2;i<=1000;i++) {
        if(!prime[i])
        for(j=i+i;j<=1000;j+=i)
        prime[j]=1;
     }
     cnt=0;
     for(i=2;i<=1000;i++) {
        if(!prime[i]) prime[++cnt]=i;
     }
     for(i=2;i<=cnt;i++) {
        int t=prime[i]+prime[i-1]+1;
        if(pri(t)) pre[t]=1;
     }
     for(i=1;i<=1000;i++) {
        pre[i]+=pre[i-1];

     }
 }

 int main()
 {
    init();
    int n,k;
    while(scanf("%d%d",&n,&k)!=EOF)
    {
        if(pre[n]>=k) printf("YES\n");
        else printf("NO\n");
     }
     return 0;
 }



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

D - Noldbach problem CodeForces - 17A

Nick is interested in prime numbers. Once he read about Goldbach problem. It states that every even ...

【水遍历\打表】#17 A. Noldbach problem

A. Noldbach problem time limit per test 2 seconds memory limit per test 64 megabytes ...
  • okcd00
  • okcd00
  • 2014年05月07日 17:16
  • 517

CodeForces 17A Noldbach problem

Description Nick is interested in prime numbers. Once he read about Goldbach problem. It states t...

Problem 17

Problem If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there ...

hihoCoder挑战赛17 A String Problem I 题库 1260

题意中文题:http://hihocoder.com/problemset/problem/1260思路 建一个字典树,暴力dfs求解每个提问 实现#include #include #inclu...

HDU 1016.Prime Ring Problem【DFS(递归)】【素数打表】【8月17】

Prime Ring Problem Problem Description A ring is compose of n circles as shown in diagram. Put na...

Problem 17:Number letter counts

原题链接:http://projecteuler.net/problem=17 If the numbers 1 to 5 are written out in words: one, ...

欧拉项目 Problem 17 of how many letters would be used?

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + ...

2013-3-17 集训 Problem H: 跳格子 搜索

点击打开链接 Description  今天小云和小塘玩起了跳格子的游戏,小云对小塘说: 我在地上给你画一些格子,格子里面会出现下面的这些符号 ‘S’ ...

Project Euler: Problem 17 Number letter counts

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + ...
  • youb11
  • youb11
  • 2015年05月31日 10:04
  • 469
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CodeForces-17A-Noldbach problem
举报原因:
原因补充:

(最多只允许输入30个字)