Algorithm for checking Prime Power

1.2k Views Asked by At

Suppose we are given some arbitrary positive integer. How can we check whether the integer is a prime power? Brute force would be very inefficient in this case.

1

There are 1 best solutions below

1
On

There are "essentially linear time" algorithms to check wether a number is a perfect power (see also this paper).

After that you can check wether the number is prime using one of the many known primality test (Miller-Rabin is probably the best combination of ease to implement and speed if you're not dealing with huge numbers)