HDOJ 题目 3792 Twin Prime Conjecture(数学)
来源:互联网 发布:征途打鱼软件 编辑:程序博客网 时间:2024/05/16 06:50
Twin Prime Conjecture
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2249 Accepted Submission(s): 720
Problem Description
If we define dn as: dn = pn+1-pn, where pi is the i-th prime. It is easy to see that d1 = 1 and dn=even for n>1. Twin Prime Conjecture states that "There are infinite consecutive primes differing by 2".
Now given any positive integer N (< 10^5), you are supposed to count the number of twin primes which are no greater than N.
Now given any positive integer N (< 10^5), you are supposed to count the number of twin primes which are no greater than N.
Input
Your program must read test cases from standard input.
The input file consists of several test cases. Each case occupies a line which contains one integer N. The input is finished by a negative N.
The input file consists of several test cases. Each case occupies a line which contains one integer N. The input is finished by a negative N.
Output
For each test case, your program must output to standard output. Print in one line the number of twin primes which are no greater than N.
Sample Input
1520-2
Sample Output
014
Source
浙大计算机研究生保研复试上机考试-2011年
Recommend
notonlysuccess | We have carefully selected several similar problems for you: 3874 1568 3641 3430 1573
题意
twins prime:素数b-素数a==2,
求0-n有多少twins prime
ac代码
#include<stdio.h>#include<string.h>#include<math.h>int a[100010],b[100010],cot;void fun(){int i,j,w;cot=1;a[0]=2;for(i=3;i<100010;i++){w=1;for(j=2;j<=sqrt(i);j++){if(i%j==0){w=0;break;}}if(w)a[cot++]=i;}}int main(){int i,j,k,t,n,ans=0;fun();t=2;for(i=1;i<cot;i++){//b[i]=b[i-1];if(a[i]-t==2)ans++;t=a[i];b[a[i]]=ans;}j=0;for(i=0;i<100010;i++){if(b[i]>j)j=b[i];b[i]=j;}while(scanf("%d",&n)!=EOF,n>=0){printf("%d\n",b[n]);}}
0 0
- HDOJ 题目 3792 Twin Prime Conjecture(数学)
- hdu 3792 Twin Prime Conjecture
- hdu 3792 Twin Prime Conjecture
- HDU 3792Twin Prime Conjecture
- HDU 3792——Twin Prime Conjecture(数论)
- 素数 hdu 3792 Twin Prime Conjecture
- 杭电 3792 Twin Prime Conjecture
- HDU3792---Twin Prime Conjecture(树状数组)
- Twin Prime Conjecture + 数论
- hdoj3792 Twin Prime Conjecture
- HDU 3792 Twin Prime Conjecture(素数筛法 + 树状数组)
- hdu 3792 Twin Prime Conjecture 浙大复试上机题 水题
- hdu3792 Twin Prime Conjecture(树状数组+线性筛)
- zju2011保研:Twin Prime Conjecture
- hdu 3792 Twin Prime Conjecture n之内的孪生素数个数
- hdu 3792 Twin Prime Conjecture n之内的孪生素数个数
- hdu3792(Twin Prime Conjecture) and hdu1541(Stars)树状数组
- HDOJ 题目Largest prime factor(水题)
- zoj 3816 Generalized Palindromic Number(枚举加构造)
- 字符编码常识及问题解析
- webkit加载网页
- 为GridView添加HeaderView
- java md5加密算法
- HDOJ 题目 3792 Twin Prime Conjecture(数学)
- 关于Java编程实现n个小球涂色的问题
- 计算机网络概述(第二周)
- formValidator的一些验证实例
- 中国概念股周二早盘多数下跌 猎豹移动跌超3%
- 数位DP
- 计算月份天数包括闰年二月天数计算
- ORA-01461: 仅可以为插入 LONG 列的 LONG 值赋值
- Pig、Hive、Map Reduce 解决分组 Top K 问题