Efficient Determination of prime numbers and Determination of prime numbers

Source: Internet
Author: User

Efficient Determination of prime numbers and Determination of prime numbers

Twin Prime Number: the so-called twin prime number refers to the adjacent prime number with an interval of 2, and the distance between them is no longer near.


If n is ≥6 and N-1 and n + 1 are twin prime numbers, n must be a multiple of 6. Proof: When N-1 and n + 1 are prime numbers, then there are numbers between them, where ① between N-1 and n + 1 are odd numbers, where n is an even number, that is to say, n is a multiple of 2, where n is not a multiple of 3. n = 3x + 1 or n = 3x + 2. If n = 3x + 1, n-1 = 3x, which is contrary to ①, so n = 3x + 1; if n = 3x + 2, n + 1 = 3 (x + 1), and ①, therefore, n = 3x + 2; n is a multiple of 3, and n is a multiple of 6.
From the above law, we can draw the following conclusion: If x contains 1 and n = 6x-1 or n = 6x + 1 is not a prime number, n must not be a multiple of 2 and 3. Proof: Limit n = 6x-1 or n = 6x + 1, that is, n = 2 (3x)-1 or n = 2 (3x) + 1 or n = 3 (2x) -1 or n = 3 (2x) + 1. Limit n must not be a multiple of 2 and 3.
Regular Expression of prime numbers: WHEN n reaches 5, if n is a prime number, n mod 6 = 1 or n mod 6 = 5, that is, n must appear in 6x (x ≥ 1). Proof: when x is greater than or equal to 1, the following representation is provided: 2017100006x, 6x + 1, 6x + 2, 6x + 3, 6x + 4, 6x + 5, 6 (x + 1), 6 (x + 1) + 1. The number of rows not on both sides of 6x is 6x + 2, 6x + 3, 6x + 4, that is, 2 (3x + 1), 3 (2x + 1), 2 (3x + 2), they must not be prime numbers, so prime numbers must appear on both sides of 6x.
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #define LL long long  6 using namespace std; 7 int n,m,p; 8 bool judge(int num) 9 {10     if(num==2||num==3)11     return true;12     13     if(num%6!=1&&num%6!=5)14     return false;15     16     for(int i=5;i*i<=num;i+=6)17         if(num%i==0||num%(i+2)==0)18         return false;19     20     return true;21 }22 int main()23 {24     scanf("%d%d",&n,&m);25     for(int i=1;i<=m;i++)26     {27         scanf("%d",&p);28         if(judge(p)&&p!=1)printf("Yes\n");29         else printf("No\n");30     }31     return 0;32 }

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.