Let's define the DN as: DN = PN+1-PN, where pi is the number I prime. Obviously there are d1=1 and the DN for n>1 is even. "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 (< 105), please 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
1 ImportJava.util.Scanner;2 3 Public classMain4 {5 Public Static BooleanJudintx)6 {7 for(intI=2;I<=MATH.SQRT (x); i++)8 if(x%i==0)9 return false;Ten return true; One } A Public Static voidMain (String[]args) - { - //System.out.println ("...."); theScanner in=NewScanner (system.in); - intn=in.nextint (); - intp1,p0; - intCout=0; +p0=2; -P1=3; + for(inti=4;i<=n;i++) A { at if(Jud (i)) - { -p0=P1; -p1=i; - if(p1-p0==2) -cout++; in } - } to System.out.println (cout); + } -}
00-Self Test 2. Prime pair conjecture (20)