-
-
[原创]自己用python写的一个用于素因子分解的程序
-
发表于: 2013-12-20 12:16 3291
-
def getfactors(key):
list_factors=[]
for i in range(2,key+1):
if key%i==0 and isprime(i)==1:
list_factors.append(i)
return list_factors
def isprime(to_judge):
if to_judge==2:
return 1
else:
for j in range(2,to_judge):
if to_judge%j==0:
return 0
if j==to_judge-1:
return 1
def maxmium(value):
if value==1:
return 1
else:
list_prime=getfactors(value)
l=len(list_prime)
return list_prime[-1]
def main():
value=int(raw_input('Please input a number:'))
max_prime=maxmium(value)
list_max=[]
key=0
while key!=1:
key=value/max_prime
list_max.append(max_prime)
value=key
max_prime=maxmium(value)
print list_max
main()
运行良好,请指正!
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课