SHARE
TWEET

perfectpower

phillip1882 Mar 14th, 2012 142 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import math
  2.  
  3. def introot(value,root):
  4.    a = root
  5.    b = 0
  6.    while math.fabs(a-b) > 0:
  7.       b = a
  8.       a = int(1.0/root *((root-1.0)*a +value/a**(root-1.0)))
  9.    return a  
  10.        
  11. def isperfectpower(value):
  12.    minE,maxE,minB,maxB = 2,int(math.log(value,2)),2,introot(value,2)
  13.    while minB**maxE != value and maxB**minE != value and minE < maxE:
  14.          minE += 1
  15.          maxB = introot(value,minE)
  16.          minB += 1
  17.          maxE = int(math.log(value,minB))  
  18.          if minB**maxE == value or maxB**minE == value:
  19.             return True
  20.    return False
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top