Prime pair conjecture (20 points)

Prime number conjecture (20 points)
Let us define dn as: d​n​​ =p​n+1−p​n, where p​i​​ is the i-th prime number. Obviously d​1​​ =1, and d​n is even for n>1. The "prime pair conjecture" believes that "there are infinitely many pairs of adjacent prime numbers with a difference of 2".
Now given any positive integer N (<10^5​​), please count the number of prime number pairs that do not exceed N that satisfy the conjecture.

Input format:
Input a positive integer N in one line.

Output format:
Output the number of prime number pairs that do not exceed N and satisfy the conjecture in one line.

Input sample:

20

Sample output:

4

Problem-solving code:

#include<iostream>
#include<cmath> 
using namespace std;
int pd(int n){
    
    
	if(n<=1) return 0;
	int i;
	for(i=2;i*i<=n;i++)
	{
    
    
		if(n%i==0) return 0;
	}
	return 1;
}
int main()
{
    
    
	int n;
	cin>>n;
	int i,s=0;
	for(i=3;i+2<=n;i+=2)
	{
    
    
		if(pd(i)&&pd(i+2)) 
		s++;
	}
	cout <<s<<endl; 
	return 0;

}


Welcome to the advice of the big guys, if you don’t understand the cute ones, you can privately message q2651877067, I am very happy to answer QwQ for you! ! !

Guess you like

Origin blog.csdn.net/mmmjtt/article/details/115278217