我需要三个正整数的每个组合,总和为1000.
这是我的尝试,但我不确定这是否正确,因为我无法验证它.
def getSum():
l = []
for x in range(1, 999):
total = 1000-x
for y in range(1, 999):
total = total-y
if total>0:
l.append([x, y, total])
return l
print len(getSum())
Run Code Online (Sandbox Code Playgroud)
我得到了28776种不同的组合.那是对的吗?