Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def factorize( n ):
- assert type(n) in (int, long)
- assert n > 0
- div = 2
- while div <= n:
- if n % div == 0:
- n /= div
- yield div
- else:
- div += 1
- def gcd( a, b ):
- while b > 0:
- a, b = b, a % b
- return a
- def count_values( values ):
- res = {}
- for value in values:
- if not value in res:
- res[ value ] = 0
- res[ value ] += 1
- return res
- def whatpower(n):
- if 1 == n: return (1,1)
- fc = count_values( factorize( n ) )
- p = reduce( gcd, fc.values() )
- b = reduce( lambda x,y: x*y, map( lambda x:(x[0]**(x[1]/p)), fc.items()) )
- return (b,p)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement