【发布时间】:2019-10-02 00:22:00
【问题描述】:
我正在使用 python 做一个数学难题,在这里你可以找到 k 位长的数字序列,其中每个数字的乘积等于数字之和,即 k=3 1*2*3 = 1 +2+3
我是 python 和一般编程的新手,我很好奇为什么会有一个“下降”,它可以非常快地评估到某个点,然后程序就会卡住。
p>psnumbers = []
#this gives me a number to start a for loop later in the script
def ones(n):
string = '1'*n
return int(string)
#multiplies and adds the digits together and compares the values
def check(n):
global psnumbers
add = 0
mult = 1
for i in range(len(n)):
add += int(n[i])
mult*= int(n[i])
if add == mult and n[0] != 0:
print(n)
psnumbers.append(n)
return True
else:
return False
#starts checking numbers, starting with the value from ones()
def loop(n):
for x in range(2,n+1):
for i in range(ones(x),ones(x)*2):
if check(str(i)) == True:
break
else:
continue
#loop(23) works for me fine, but loop(n) where n>=24 doesn't finish processing
loop(23)
loop(n) 的所有值,其中 n
【问题讨论】:
-
据我所知,该属性没有 24 位数字。你只需要检查
标签: python