An integer p greater than one is prime iff the only divisors of p are 1 and p. First few prime numbers are 2, 3, 5, 7, 11, 13, …
The Lehmann’s test is a probabilistic primality test for an natural number n, it can test the primality of any kind of number(whether a large odd number is prime or not). The Lehmann’s test is a variation of Fermat’s Primality Test.
The approach used is as follows:
If ‘n’ is an odd number and ‘a’ is a random integer less than n but greater than 1, then
x = (a^((n-1)/2)) (mod n)
It is computed.
- If x is 1 or -1(or n-1), then n may be prime.
- If x is not 1 or -1(or n-1), then n is definitely composite.
The fact that any composite number can be turned out to be a prime, in this case, depends on the random value ‘a’. If all the values of a and n are co-prime, then n can be said as a prime number.
Example-1: Input: n = 13 Output: 13 is Prime Explanation: Let a = 3, then, 3^((13-1)/2) % 13 = 729 % 13 = 1 Hence, 13 is Prime. Example-2: Input: n = 91 Output: 91 is Composite Explanation: Let a = 3, then, 3^((91-1)/2) % 91 = 27 Hence, 91 is Composite.
13 may be Prime.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- AKS Primality Test
- Python - Test if List contains elements in Range
- Python - Test if common values are greater than K
- Python | Test list element similarity
- Python | Test for False list
- Python | Test if string contains element from list
- Python | Test for nested list
- Python | Test if all elements are present in list
- Python | Test if any list element returns true for condition
- Python | Test if element is dictionary value
- Python | Test if tuple is distinct
- Python | Test if key exists in tuple keys dictionary
- Python - Test if Tuple contains K
- Python - Test for strictly decreasing list
- Python - Test rear digit match in all list elements
- Python - Test if a list is completely True
- Python | Least Value test in Dictionary
- Python | K occurrence element Test
- Python | Even Front digits Test in List
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.