数组·1·素数对猜想
来源:互联网 发布:淘宝学生女装店 知乎 编辑:程序博客网 时间:2024/06/04 18:10
_
7-5 素数对猜想(20 分)
让我们定义dn为:dn=pn+1−pn,其中pi是第i个素数。显然有d1=1,且对于n>1有dn是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。
现给定任意正整数N
(<105),请计算不超过N
的满足猜想的素数对的个数。
输入格式:
输入在一行给出正整数N
。
输出格式:
在一行中输出不超过N
的满足猜想的素数对的个数。
输入样例:
20
输出样例:
4
#include<stdio.h>
int main()
{
int N,i,j,m=1,count=1;
scanf("%d",&N);
if(N==1&&N==2&&N==3&&N==4)
printf("0");
else{
for(i=2;i<=N;i++)
{ m=m+2;
for(j=2;j<=m;j++){
if(m%i==0)
break;
if(j>m)
count++;}
if(m>N)
break;
} printf("%d",count);}
return 0;
}
_____________________________________________________________
- #include <stdio.h>
- #include <math.h>
- #include <stdbool.h>
- bool isPrime(int);
- int main(void)
- {
- int N,i;
- int count = 0;
- scanf("%d", &N);
- if (N <= 4)
- printf("0");
- else
- {
- for (i = 3; i <= N - 2; i++)
- if (isPrime(i) && isPrime(i + 2))
- count++;
- printf("%d",count);
- }
- return 0;
- }
- bool isPrime(int n)
- {
- int i;
- if (n == 1 || n == 0)
- return false;
- else
- {
- for (i = 2; i <= sqrt((double)n); i++)
- if (n%i == 0)
- return false;
- }
- return true;
- }
__________________________________________________________________
阅读全文
0 0
- 数组·1·素数对猜想
- PAT1007. 素数对猜想
- 1007 素数对猜想
- 1007. 素数对猜想
- 1007. 素数对猜想
- 素数对猜想 (20)
- PAT素数对猜想
- 素数对猜想
- 1007. 素数对猜想
- 素数对猜想
- 素数对猜想
- 1007素数对猜想
- PAT1007. 素数对猜想
- 素数对猜想
- 1007.素数对猜想
- 1007. 素数对猜想
- pat1007:素数对猜想
- 1007. 素数对猜想
- JavaScript忍者秘籍笔记01之函数
- go install 基本使用
- 51Nod-1137-矩阵乘法
- 1049. 数列的片段和(20)
- 最大上升子序列(从前往后) nlogn 和最大上升序列(从后往前)
- 数组·1·素数对猜想
- 用Python+StanfordCoreNLP做中文命名实体分析
- path-sum
- mybatis-config.xml配置文件
- 后台运行VirtualBox虚拟机
- 修改hexo的主题nexT中的Pisces主题宽度
- 【AssetBundle】ab释放导致Texture多份
- 安装IPython Notepad
- 阶乘算法