![]() |
VOOZH | about |
Vantieghems Theorem is a necessary and sufficient condition for a number to be prime. It states that for a natural number n to be prime, the product of where , is congruent to .
In other words, a number n is prime if and only if.
Examples:
Another way to state above theorem is, if divides , then n is prime.
2 is prime 3 is prime 5 is prime 7 is prime
Time Complexity : O(limit)
Auxiliary Space: O(1)
The above code does not work for values of n higher than 11. It causes overflow in prod evaluation.