Ideas See: http://blog.csdn.net/code_pang/article/details/7880245
Twin primes: The so-called twin primes refer to the adjacent primes with an interval of 2.
More than 6 of the number of twin primes,
P-1 and p+1 are prime, then P-1 and p+1 must be odd, then p must be even, that is, p is a multiple of 2!
P-1, p, p+1 for a continuous natural number, they must have a multiples of 3, P-1 and p+1 for prime numbers, then they are not multiples of 3, that is, P is also a multiple of 3!
So p must be 2 and 3 least common multiple that is a multiple of 6!
N≥6 and N-1 and n+1 are twin primes, then n must be a multiple of 6.
Prove:
∵n-1 and n+1 are prime ┈┈┈┈┈①
∴n-1 and n+1 are odd
∴n is an even number, that is, N is a multiple of 2 ┈┈┈┈┈②
Assuming that n is not a multiple of 3, get:
N=3x+1 or N=3x+2,
If n=3x+1, then n-1=3x, and ① against, so n≠3x+1;
If n=3x+2, then n+1=3 (x+1), and ① against, so n≠3x+2;
∴ hypothesis is not established, that is, N is a multiple of 3, and there is a ② conclusion:
N is a multiple of 6.
The following conclusions can be drawn from the above rules:
If x≧1 and n=6x-1 or n=6x+1 are not primes, then n must not be multiples of 2 and 3.
Prove:
∵n=6x-1 or n=6x+1, i.e. n=2 (3x)-1 or n=2 (3x) +1 or n=3 (2x)-1 or n=3 (2x) +1.
∴n must not be multiples of 2 and 3.
The rule of prime number:
When n≧5, if n is prime, then n mod 6 = 1 or n mod 6 = 5, i.e. n must appear on either side of 6x (x≥1).
Prove:
When x≥1, there are the following representations:
6x,6x+1,6x+2,6x+3,6x+4,6x+5,6(x+1),6(x+1)+1
The numbers on both sides of the 6x are 6x+2,6x+3,6x+4, i.e. 2 (3x+1), 3 (2x+1), 2 (3x+2), they must not be primes, so the prime number must appear on both sides of the 6x.
The judging code is as follows:
BOOLIsPrime (intNUM) {if(num==1)return false;//Pay attention to the special award if(num==2|| num==3)return true;if(num%6!=1&& num%6!=5)return false; for(inti =5; i*i <= num; i+=6)if(num% i = =0|| num% (i+2) ==0)return false;return true;}
Only on behalf of personal views, welcome to Exchange discussion, do not spray ~ ~ ~
Photoby:wlop
Http://weibo.com/wlop
Judging prime numbers by using twin primes