Given a number N and a base number A. The task is to check whether the number is a Fermat Pseudoprime to the base.
The number N is called as Fermat Pseudoprime to the base A, if
1. A > 1
2. N is a composite number
3. N divides AN-1 – 1.
Input : N = 645, a = 2
645 = 3*5*43, Hence it is a composite number
Also 645 divides 2^(644)-1
Hence it is a Fermat Pseudoprime.
Input : N = 6, a = 2
Approach: The approach is to check the below conditions:
- Check if A > 1.
- Check if N is a composite number.
- Check if N divides AN-1 – 1.
If all of the above conditions satisfy then N is a fermat pseudoprime to base A.
Below is the implementation of the above approach:
Time Complexity : O(sqrt(N))
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check if a number is Euler Pseudoprime
- Fermat's little theorem
- Fermat's Last Theorem
- Fermat's Factorization Method
- Compute nCr % p | Set 3 (Using Fermat Little Theorem)
- Program to find first N Fermat Numbers
- Primality Test | Set 2 (Fermat Method)
- Fermat's Factorization method for large numbers
- Check if a number is divisible by all prime divisors of another number
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Check if the number is a Prime power number
- Check if a number with even number of digits is palindrome or not
- Program to check whether a number is Proth number or not
- Check whether the given number is Euclid Number or not
- Check if a number is an Unusual Number or not
- Check if a number is a Mystery Number
- Check if a number is a Trojan Number
- Check if a number is an Achilles number or not
- Check whether a number is Non-hypotenuse number
- Check if a number ends with another number or not
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.