Sieve prime number method (2) - Fermat's little theorem and MR prime number judgment

Note: x y in this article means x to the power of y

1. Fermat's little theorem

1.1 Contents
If p is a prime number, a is a positive integer, and gcd(a,p)=1, then a p−1 ≡1(mod p).
1.2 Prove that
because p is a prime number, so gcd(i,p)=1(1<=i<=p-1, i is an integer), it can be deduced that ①gcd((pi)!,p)=1 , and because gcd( a,p)=1, so gcd(i∗a,p)=1, then ② no i*a is a multiple of p
Set a=b*p+r, then gcd(i*r,p)=1, no i*r is a multiple of p.
Suppose there are two i*r congruence mod p, then c*r≡d*r(mod p)(c<d), then (dc)*r≡0(mod p), that is p|(d− c)∗r. Since 1<=d−c<=p−1, this contradicts no i*r that is a multiple of p. Therefore, there are no two congruences and modulo p in i*r to prove, that is, there are no two congruences and modulo p in ③i*a
Having proved ①②③, we can prove Fermat’s little theorem: 
because of ②③, we can know that i*a%p must be an arrangement of 1,2,3,…,p-1, that is: 
a∗2a ∗3a∗…∗(p−1)a≡1∗2∗3∗…∗(p−1)(mod p), that is: 
(p−1)!∗a p−1 ≡(p−1)! (mod p) 
Because of ①, it can be divided by (p-1)! to get a p−1 ≡1(mod p) , Fermat's little theorem is proved.


2. MR prime number judgment (advantage: fast speed disadvantage: low accuracy)

2.1 Method
Miller-Rabin prime number test (referred to as MR prime number test) uses Fermat's little theorem to quickly determine whether a number is a prime number, but because this method only has a high probability of not making errors, it is not completely correct, so in sufficient time It is not necessary to use this method in this case.
2.2 Implementation
Because when n is a prime number and gcd(a,n)=1, a n−1 ≡1(mod n), so we can randomize several a to increase the accuracy of the algorithm, and then judge a n−1 ≡1(mod n) is not established. Since a n−1 ≡1(mod n) hardly holds when n is not a prime number, if a n− 1 ≡1(mod n) holds true after multiple a tests , it is considered that n is a prime number. But there is also such a composite number, for any p is prime, gcd(a,p)=1, then a p−1 ≡1(mod p) is true. This number is called the Carmichael number. Of course, such numbers are very few, there are only 255 Carmichael numbers among the integers in the range of 1 to 100,000,000. When it comes to Carmichael numbers, MR prime judgment is useless. Therefore, in the case of ample time, it is best to use a linear sieve .



Note: If you have learned Fermat's little theorem and MR prime number judgment through this literature, please like and leave. Of course, you are also welcome to point out the shortcomings of this article in the discussion area. The author will correct this article in time
. Copyright statement: Please indicate the address for reprinting

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325756924&siteId=291194637