Today I think more of the problem is not a come out now. Let's update the topic of the afternoon. It's almost 0 o'clock. Helpless Ah.
Problem Description:
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 is one line, not exceeding N's number of prime pairs that satisfy the conjecture.
Input Sample:
20
Sample output:
4
The code is as follows:
1#include <stdio.h>2#include <math.h>3 inta[100005]={0};4 intIsPrime (intnum);5 intMain ()6 {7 intnum;8scanf"%d",&num);9 intflag1=2, flag2=0;Tena[2]=2; One for(intI=3; i<=num;i++){ A if(IsPrime (i)) { -flag1++; -A[FLAG1] =i; the if((a[flag1]-a[flag1-1])==2){ -flag2++; - } - } + } -printf"%d", Flag2); + return 0; A } at intIsPrime (intnum) { - intflag=1; - inttemp=sqrt (num); - for(intI=2; i<=temp;i++){ - if(num%i==0){ -Flag =0; in } - } to returnFlag; +}
Thinking Analysis:
The Prime number table first writes 0, the second item is 2, and then iterates through is not the prime number. The prime pair satisfies the conjecture, and the counter is + +.
= = First of all, I'm going to have a better question for today.
pat_1007 prime number pair conjecture