だから私はここにこの問題があります:
3 または 5 の倍数である 10 未満の自然数をすべてリストすると、3、5、6、および 9 になり
ます。これらの倍数の合計は 23
です。1000 未満の 3 または 5 のすべての倍数の合計を見つけます。
そして、私はここにこれを書きました:
def multiples(num, below):
counter = 1
z = 0
while True:
x = num * counter
if x < below:
z += x
else:
break
counter += 1
return z
below = 1000
print "Multiples of 3: " + str(multiples(3, below))
print "Multiples of 5: " + str(multiples(5, below))
print "Added: " + str(multiples(3, below) + multiples(5, below))
10に設定below
すると、正しい答え 23 が得られます
Multiples of 3: 18
Multiples of 5: 5
Added: 23
しかし、これを 1000 に設定すると、次のようになります。
Multiples of 3: 166833
Multiples of 5: 99500
Added: 266333
そして、これは間違っていると思われます。私が得ていないものはありますか?