pre_exam exercise 3
>>> single_factors(2)
2
>>> single_factors(4096) # 4096 == 2**12
2
>>> single_factors(85) # 85 == 5 * 17
85
>>> single_factors(10440125) # 10440125 == 5**3 * 17**4
85
>>> single_factors(154) # 154 == 2 * 7 * 11
154
>>> single_factors(52399401037149926144) # 52399401037149926144 == 2**8 * 7**2 * 11**15
154
def single_factors(number): dic_number={} for i in range(2,number+1): #这里一定是加1,不然当factor为质数时返回的结果只有1 while number%i==0: dic_number[i]=dic_number.get(i,0)+1 number=number//i #采用//可以极大的节约等待时间,因为操作对象是证书而不再是浮点数 if number==1: break final=1 for m in dic_number.keys(): final=final*m return final a=single_factors(52399401037149926144) print(a)