Mason Prime Number decision template

Source: Internet
Author: User

For a prime A,2^a-1 is called the mason number. If the 2^a-1 is a prime number, it is called the Mason Prime.

We know that if a is composite, then 2^a-1 must not be a prime number.

2^a-1 is a prime number, a must be a prime number.

If A is a prime number, then the 2^a-1 can be a prime number, or it can be composite.

UnsignedLong LongMulti_pow (unsignedLong Longx,unsignedLong Longx1,unsignedLong LongMoD) {unsignedLong Longsum=0;  while(x1) {if(x1&1) sum = (sum+x)%MoD; X1>>=1; X= (x<<1)%MoD; }    returnsum;}BOOLCheck_primemason (intN//Test 2^n-1 is not a prime number{unsignedLong LongR=4; unsignedLong Longmod= (unsignedLong Long) (1ll<<n)-1;  for(intI=2; i<n;i++) {R=Multi_pow (R,R,MOD); R= (r2+MOD)%MoD; }    if(n==1)return 0; if(n==2)return 1; if(r==0)return 1; return 0;}

Mason Prime Number decision template

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.