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))
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Check if a number is Euler Pseudoprime
- Fermat's little theorem
- Fermat's Last Theorem
- Compute nCr % p | Set 3 (Using Fermat Little Theorem)
- Fermat's Factorization Method
- 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
- Program to check whether a number is Proth number or not
- Check if a number with even number of digits is palindrome or not
- Check if a number is Flavius Number
- Check whether a number is Non-hypotenuse number
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.