17A Noldbach problem

A. Noldbach problem
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Examples
input
27 2
output
YES
input
45 7
output
NO
Note

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.


题意:输入一个数n和k,求2到n之间的素数然后求他们中素数满足2到n之间相邻两个素数和再加1的个数,如果个数>=k就输出YES,否则就NO。

题解:用线性筛,直接筛选出2到n范围中的素数,最后暴力判断个数。

#include
using namespace std;
const int N=1010;
int a[N],vis[N];
int n,k,cnt;
void init()
{
  cnt=0;
    memset(vis,0,sizeof(vis));
    for(int i=2; i<=n; i++)
    {
        if(!vis[i])
        {
            a[cnt++]=i;
            for(int j=2*i; j<=n; j+=i)
                vis[j]=1;
        }
    }
}
int main()
{
    int ans;
    while(cin>>n>>k)
    {
        ans=0;
        init();
        for(int i=0; i<=cnt; i++)
            for(int j=1; j=k?"YES":"NO");
    }


    return 0;
}


你可能感兴趣的:(ACM日常水题练习集)