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.*;2 3 Public classMain {4 Private StaticMap<integer,boolean> map=NewHashmap<integer,boolean>();5 Private Static BooleanIsPrime (intnum) {6 if(Map.get (num)! =NULL)returnmap.get (num);7 for(intI=2;I<=MATH.SQRT (num); i++){8 if(num%i==0) {9Map.put (NUM,false);Ten return false; One } A } -Map.put (NUM,true); - return true; the } - - - Public Static voidMain (string[] args) { +Scanner in =NewScanner (system.in); - intSize=0; + while(In.hasnext ()) { A intn=in.nextint (); at intCount=0; - for(inti=5;i<=n;i+=2){ - if(IsPrime (i) &&isprime (i-2)){ -count++; - } - } in System.out.println (count); - to } + } -}
1007. Prime number pairs conjecture (20)