import math
def introot(value,root):
a = root
b = 0
while math.fabs(a-b) > 0:
b = a
a = int(1.0/root *((root-1.0)*a +value/a**(root-1.0)))
return a
def isperfectpower(value):
minE,maxE,minB,maxB = 2,int(math.log(value,2)),2,introot(value,2)
while minB**maxE != value and maxB**minE != value and minE < maxE:
minE += 1
maxB = introot(value,minE)
minB += 1
maxE = int(math.log(value,minB))
if minB**maxE == value or maxB**minE == value:
return True
return False