Let's define DN as: Dn = Pn+1-pN, where Pi is the first prime. Obviously there is D1=1 and for n>1 thereis an even number of D N. "The prime number pairs conjecture" that there are infinitely many pairs of adjacent and the difference is 2 primes.
Now given any positive integer n (<5), calculate the number of prime pairs that do not exceed N to satisfy the conjecture.
input Format: each test input contains 1 test cases, giving a positive integer n.
output format: the output of each test case occupies one line, not exceeding N of the number of prime pairs that satisfy the conjecture.
Input Sample:
20
Sample output:
4
#include <iostream> using namespace std; BOOL IsPrime (unsigned long N) //The prime number of the Web check method { if (n <= 3) { return n > 1; } else if (n% 2 = = 0 | | n% 3 = = 0) { return false; } else{for (unsigned short i = 5; I * I <= n; i + = 6) { if (n% i = = 0 | | n% (i + 2) = = 0) { return false; } } return true; } } int main () { int i,j=0,n,c[100000],count=0; cin>>n; for (i=1;i<=n;i++) { if (IsPrime (i)) c[j++]=i; } for (i=j-1;i>=1;i--) { if ((c[i]-c[i-1)) ==2) count++; } cout<<count<<endl; return 0; }
The following is written by oneself, not all points.
#include <iostream>
#include <cmath>
using namespace Std;
int main ()
{
int N;
cin>>n;
int a[100000];
a[0]=2,a[1]=3;
int k=2,num=0;
for (int i=3;i<=n;i++)
{
for (int j=2;j<=int (sqrt (i)); J + +)
{
if (i%j!=0)
{
A[k]=i;
k++;
}
}
}
for (int i=1;i<=k;i++)
{
if (a[i]-a[i-1]==2)
num++;
}
cout<<num<<endl;
return 0;
}
00-Self Test 2. Prime pair conjecture (20)