如果一个数能表示成 p^q,且p是一个素数,q为大于1的正整数,则此数就是超级素数幂
return: 如果是,返回p和q,如果不是,返回False
import math
def get_prime(number):
'''
寻找小于number的所有的质数,时间复杂度o(n^2)
'''
if number <= 1:
print 'Wrong given number.'
return
prime = []
for i in xrange(2, number+1):
j = 2
while j < i:
if i % j == 0:
break
j += 1
if j == i:
prime.append(i)
return prime
def super_prime_power(number):
scope = int(math.ceil(math.sqrt(number))) # 开根号除掉一部分不需要的数
prime_number = get_prime(scope)
be_tested = []
for i in prime_number: # 先将无法被整数的排除掉
if number % i == 0:
be_tested.append(i)
for p in be_tested:
q = 2
while p ** q <= number:
if p ** q == number:
return (p, q)
q += 1
return False