I need to test primality on intervals between numbers which are really big (in the range of long long), so i need some fast algorithm for checking if a number is prime or not. Please suggest your ideas.
For large integers, the most efficient primality tests are pro- babilistic. However, for integers with a small fixed number of bits the best tests in practice are deterministic. Currently the best known tests of this type involve 3 rounds of the Miller-Rabin test for 32-bit integers and 7 rounds for 64-bit integers.
Fast deterministic tests The first deterministic primality test significantly faster than the naive methods was the cyclotomy test; its runtime can be proven to be O((log n)clogloglogn), where n is the number to test for primality and c is a constant independent of n.
The time complexity of the Miller-Rabin Primality Test is O ( K ∗ l o g 3 ( N ) O(K*log^3(N) O(K∗log3(N), where N is the number to be checked for primality, and K is the number of iterations performed for accuracy as per the requirement.
Well-known Monte Carlo algorithms include the Solovay–Strassen primality test, the Baillie–PSW primality test, the Miller–Rabin primality test, and certain fast variants of the Schreier–Sims algorithm in computational group theory.
One good method is the Miller-Rabin test. It should be noted however, that this is only a probabilistic test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With