2015
04-13

# Twin Prime Conjecture

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.

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.

1
5
20
-2

0
1
4

#include <stdio.h>
#include <math.h>
int a[10000]={2},num[100000]={0,0};
int main()
{
int n,i,j,g,temp;
for(g=0,i=3;i<100000;i++)
{
temp=sqrt(i);
for(j=2;j<=temp;j++)
if(i%j==0)break;
if(j>temp)
{
a[g]=i;
num[i]=num[i-1]+(a[g-1]+2==a[g]?1:0);
g++;
}
else
num[i]=num[i-1];
}
while(scanf("%d",&n)&&n>=0)
{
printf("%d\n",num[n]);
}
return 0;
}

1. 站长，你好！
你创办的的网站非常好，为我们学习算法练习编程提供了一个很好的平台，我想给你提个小建议，就是要能把每道题目的难度标出来就好了，这样我们学习起来会有一个循序渐进的过程！

2. 在方法1里面：

//遍历所有的边，计算入度
for(int i=0; i<V; i++)
{
degree = 0;