Of prime conjecture
Let d n is defined as: dn = p n + 1-pn, where p i is the i-th prime number. Clearly there is d 1 = 1, and for n> 1 there is an even number dn. "Primes to guess" that "there is an infinite number of adjacent and poor is a prime number 2."
Now given an arbitrary positive integer N (<10 . 5 ), does not exceed Calculate number N satisfies the conjecture of primes.
Input formats:
It gives a positive integer in the input line N.
Output formats:
In the output line does not exceed the number N satisfy the conjecture of the primes.
Sample input:
20
Sample output:
4
Ideas:
3 and 5 are the first difference value is a prime number of from i = 3 starts verification i and i + 2 (less than N) whether, C language from 2 to root N, whether there is a prime number by N Analyzing the case of a number divisible is prime, the number of primes index records, the condition index ++, the final output value of index.
Code:
#include <stdio.h>
#include <math.h>
int judge(int n);
int main()
{
int i,n,index;
scanf("%d",&n);
index=0;
for(i=3;i<n;i++)
{
if(judge(i)&&judge(i+2)&&i<=n-2)
index++;
}
printf("%d",index);
}
int judge(int n)
{
int i;
if(n==0||n==1)
return 0;
for(i=2;i<=sqrt(n);i++)
{
if(n%i==0)
return 0;
}
return 1;
}