The problem at the beginning of the question did not understand, or others pointed out, is to find the number of n within the difference of 2 of the number of prime pairs is how much.
When submitted, the time can not pass, the 7th line of the loop is +2, even the number is definitely not prime, directly do not judge. Line 23rd I<math.sqrt (a), can be passed.
Code:
Topic:
1007. Prime number pairs conjecture (20)
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
1007. Prime number pairs conjecture (Java)