What would be an efficient algorithm to determine if $n \in \mathbb{N}$ can be written as $n = a^b$ for some $a,b \in \mathbb{N}, b>1$?
So far, I've tried:
def ispower(n):
if n<=3:
return False
LIM = math.floor(math.log2(n))
for b in range(2,LIM+1):
a = math.pow(n, 1/b)
a_floor = math.floor(a)
print(a,a_floor)
if a == a_floor:
return True
return False
That is, checking if the $b-th$ roots are integer, for $b$ from 2 to $LIM$, where $LIM$ stands for the ultimate limit of n being a power of 2.
Thanks for your comments.