codeforces 17A Noldbach problem

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.

Sample test(s)
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以内等于两个连续素数的和加上1的数的个数 n不大于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 = 13; i <= n; ++i)
        if (isPrime (i) && find (b + 1, b + bi + 1, i) != b + bi + 1)
            ans++;
    if (ans >= k) printf ("YES\n");
    else printf ("NO\n");
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值