当用较大的整数(例如600851475143)替换x该get_large函数时,程序将停顿并且不返回值。但是,当x用较小的整数(例如20)替换时,它将返回结果。我怎样才能解决这个问题?
factors = [] # create new empty list
def calc(x):
for n in range(1, x):
if x % n == 0:
factors.append(n) # if x is divisible by n append to factor list
return factors
def get_large(x):
calc(x) # call the returned values in factors list
return calc(x)[-1] # return the last factor in the list
print("The largest factor is: " + str(get_large(600851475143)))
GCT1015
慕码人2483693
PIPIONE
相关分类