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#include <stdio.h>2#include <stdlib.h>3#include <iostream>4#include <string.h>5#include <string>6#include <math.h>7#include <algorithm>8 using namespacestd;9 Ten BOOLIsPrime (intN) One { A if(n<=1)return false; - intSQR=SQRT (1.0*n); - for(intI=2; i<=sqr;i++) the { - if(n%i==0)return false; - } - return true; + } - //Prime List + Const intmaxn=100000; A intprime[maxn]={0},num=0; at BOOLp[maxn]={0}; - voidFind_prime (intN) - { - for(intI=2; i<maxn;i++) - { - if(p[i]==false) in { -prime[num++]=i; to if(num>n) Break; + for(intj=i+i;j<maxn;j+=i) - { thep[j]=true; * } $ }Panax Notoginseng } - } the + intMain () { A the intN,count=0; +scanf"%d",&n); -Find_prime (n+1); $ for(intI=3; i+2<=n;i+=2) $ { - if(p[i]==false&&p[i+2]==false) -count++; the } -printf"%d", count);Wuyi return 0; the}
B1007. Prime pair conjecture (20)