PAT (Basic Level) Practice 1007 素数对猜想
2018-03-26 18:59
459 查看
1007. 素数对猜想 (20)
时间限制400 ms内存限制65536 kB
代码长度限制8000 B
判题程序Standard作者CHEN, Yue
让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数。显然有 d1=1 且对于n>1有 dn 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。现给定任意正整数N (< 105),请计算不超过N的满足猜想的素数对的个数。输入格式:每个测试输入包含1个测试用例,给出正整数N。输出格式:每个测试用例的输出占一行,不超过N的满足猜想的素数对的个数。输入样例:
20输出样例:
4
#include<cstdio> #include<cmath> using namespace std; bool judge(int a){ for(int i = 2; i < sqrt(a) + 1; i++) if(a % i == 0) return false; return true; } int main(){ int n; int cnt = 0; scanf("%d", &n); for(int i = 3; i + 2 <= n; i++){ if(judge(i) && judge(i+2)) cnt++; } printf("%d", cnt); return 0; }
相关文章推荐
- Pat(Basic Level)Practice--1007(素数对猜想)
- PAT BASIC LEVEL 1007. 素数对猜想 (20)
- PAT (Basic Level) Practise (中文) 1007. 素数对猜想 (20)
- PAT (Basic Level)1007. 素数对猜想
- PAT (Basic Level) Practise (中文) 1007素数对猜想 (20)
- PAT(basic level) 1007 素数对猜想
- PAT (Basic Level) Practise (中文)- 1007. 素数对猜想 (20)
- PAT乙级真题及训练集 PAT (Basic Level) Practise (中文)1007. 素数对猜想
- PAT (Basic Level) Practise (中文)1007. 素数对猜想 (20)
- PAT (Basic Level) Practise (中文)1007. 素数对猜想 (20) C语言
- PAT (Basic Level) Practise-1007. 素数对猜想 (20)
- PAT(Basic Level)_1007_素数对猜想
- PAT 乙级 Basic Level 1007. 素数对猜想(素数筛法)
- 【C++】浙大PAT (Basic Level)1007. 素数对猜想 (20)
- PAT Basic Level 1007. 素数对猜想 (20)
- 浙江大学PAT---Basic Level---1007----素数对猜想
- PAT (Basic Level) Practise (中文)1007. 素数对猜想 (20)
- PAT (Basic Level) Practise:1007. 素数对猜想
- Pat(Basic Level)Practice--1001(害死人不偿命的3n+1猜想)
- PAT Basic 1007. 素数对猜想 (20) (C语言实现)