1007. 素数对猜想
来源:互联网 发布:淘宝助理怎么关联打印 编辑:程序博客网 时间:2024/04/29 00:29
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<stdio.h>#include<math.h>#include<string.h>#include<algorithm>#define LL long longusing namespace std;int main(){ int t=0,a[10000]; for(int i=2;i<=100000;i++) { int s=(int)sqrt(i),j; for(j=2;j<=s;j++) if(i%j==0) break; if(j>s) a[t++]=i; } //printf("%d\n",t); int n,b=0; scanf("%d",&n); for(int i=1;i<t;i++) if(a[i]-a[i-1]==2&&a[i]<=n) b++; printf("%d\n",b); return 0;}
0 0
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007.素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007.素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- PAT 1007.素数对猜想
- UML类图
- poj 3764 最长异或路径(二进制trie树)
- js轮子—输入框加候选框
- Redis 秒杀
- QT系列:QString与int相互转换方法
- 1007. 素数对猜想
- Runtime.getRuntime().addShutdownHook(shutdownHook);
- FFT 学习记录
- Linux Kernel设备驱动模型之 struct device_driver
- leetcode_middle_94_106. Construct Binary Tree from Inorder and Postorder Traversal
- 浅谈GET和POST的区别
- saiku多sort改造
- android7.0 multiWindow 之拖拽失效(android事件分发机制分析)
- 函数声明放在头文件中,函数的定义放在实现文件中,然后在主函数中调用