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;
}