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))
- 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
- Primality Test | Set 2 (Fermat Method)
- Program to find first N Fermat 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 a number with even number of digits is palindrome or not
- Program to check whether a number is Proth number or not
- Check if a number is an Achilles number or not
- Check if a number is Triperfect Number
- Check if a given number is factorial of any number
- Check Whether a number is Duck 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.