Mason Prime number __ Number theory

Source: Internet
Author: User
Tags mul

A mason prime number is a positive integer, such as a 2^p-1, in which the exponent P is a prime and is often recorded as an MP. If the MP is a prime number, it is called a mason prime. p=2,3,5,7, MP is prime, but m11=2047=23x89 is not prime

The mason number may be prime or composite, so how to judge the Mason number is a key issue

According to Fermat's theorem if n is prime, there is a^ (n-1) = 1 (mod n) 1 <= a <= n-1;

A number may pass the Miller test, but he may not be prime, fortunately, this number is not much, a prime can pass all the A-based Miller test, and for a singular composite, the probability of a Miller test based on a is less than equal to 1/ 4, if an odd composite is done N times independent of the Miller Test, the probability of passing is less than (1/4) ^n, if n = 100, that (1/4) ^100 = 6.22 * 10 ^ (-61), this is a very small number, the probability of the test error is very small.

The steps of the Miller test

1. Select M A with random number.

2. Judge a^ (n-1) Second square modulo n is 1, if 1 is prime, if not 1, then is not prime. a^ (n-1) Second square modulo n can be quickly modulo completed

const int maxcnt =;

Int64 random (Int64 m)
{return
  (Int64) (rand ()%m);
Int64 Mul (Int64 a,int64 b,int64 m)
{
   Int64 sum  = 1;
   while (b > 0)
   {
       if (b%2 = = 1)
         sum = MUL (sum,a,m);
       b = B/2;
       A = MUL (a,a,m);
   }
   return sum;
}
BOOL Miller (Int64 m)
{for
    (int i = 0; I <= maxcnt i++)
    {
        Int64 a = random (m-1) +1;
        if (Mul (a,m-1,m)!= 1) return
            false;
    }
    return true;
}


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.