Codeforces 17A Noldbach problem

Source: Internet
Author: User
Tags integer numbers

Noldbach problemtime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

Nick is interested in prime numbers. Once he read aboutGoldbach Problem. It states that every even integer greater than2Can be expressed as the sum of the primes. That got Nick's attention and he decided to invent a problem of his own and call itNoldbach Problem. Since Nick is interested only in prime numbers, Noldbach problem states so at leastkPrime numbers from2ToNInclusively can be expressed as the sum of three integer numbers:two neighboring prime numbers and1. For example, +=7+ One+1, or -=5+7+1.

The prime numbers is called neighboring if there is no other prime numbers between them.

You were to help Nick, and find out if he was right or wrong.

Input

The first line of the input contains the 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 Test (s) input
27 2
Output
YES
Input
45 7
Output
NO
Note

In the first sample of the answer is YES since at least-numbers can be expressed as it's described (for Exampl E, and 19). In the second sample of the answer is NO since it's impossible to express 7 prime numbers from 2 to $ in the Desir Ed form.

n is equal to two consecutive primes and the number of 1 is not greater than 1000;

#include <cstdio> #include <cmath> #include <algorithm>using namespace std;const int N = 1000;int N, k, Ans;bool isprime (int a) {for    (int i = 2; I <= sqrt (a); ++i)        if (a% i = = 0) return 0;    return 1;} int main () {    int ai = 1, bi = 0, a[n], b[n];    A[1] = 2;    for (int i = 3; I <= N; ++i)        if (IsPrime (i))        {            A[++ai] = i;            B[++BI] = A[ai] + a[ai-1] + 1;        }    scanf ("%d%d", &n, &k);    Ans = 0;    for (int i = 1; I <= n; ++i)        if (IsPrime (i) && find (b + 1, b + bi +, i)! = B + bi + 1)            Ans++;
   if (ans >= k) printf ("yes\n");    else printf ("no\n");    return 0;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.