codeforces 17A Noldbach problem
来源:互联网 发布:郭德纲于谦 知乎 编辑:程序博客网 时间:2024/05/16 09:28
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.
The first line of the input contains two integers n (2 ≤ n ≤ 1000) and k (0 ≤ k ≤ 1000).
Output YES if at least k prime numbers from 2 to n inclusively can be expressed as it was described above. Otherwise output NO.
27 2
YES
45 7
NO
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;}
- codeforces 17A Noldbach problem
- CodeForces-17A-Noldbach problem
- Codeforces 17A Noldbach problem(数学)
- D - Noldbach problem CodeForces - 17A
- CodeForces 17 A.Noldbach problem(水~)
- 17A. Noldbach problem
- CF 17A Noldbach problem
- cf 17a Noldbach problem
- A. Noldbach problem
- 【水遍历\打表】#17 A. Noldbach problem
- cf17A Noldbach problem (素数打表)
- Problem - 152A - Codeforces
- codeforces problem/244/A
- codeforces problem/415/A
- codeforces. problem/408/A
- Codeforces Problem 333A
- Codeforces Problem 332A
- codeforces problem/416/A 二分
- linux inode信息查看命令stat
- 愛的分公司的華國鋒考核計劃
- 黑马程序员__c#基础4
- C++学习之C++对象内存模型(下)
- hdu1010--Tempter of the Bone(迷宫)
- codeforces 17A Noldbach problem
- C++ 大数类模板
- vmware中的bridge、nat、host-only的区别
- 算法导论习题解-第18章B树
- HLSL(High level shading language)
- 华为机试题(替换字符串)——Java解法
- HDU 4893 Wow! Such Sequence! 解题报告(线段树)
- Java深度历险(五)——Java泛型
- 韩语学习之第三课