How to find the sum of all the multiples of 3 or 5 below 1000 in Python?

后端 未结 18 1197
萌比男神i
萌比男神i 2020-12-29 12:10

Not sure if I should\'ve posted this on math.stackexchange instead, but it includes more programming so I posted it here.

The question seems really simple, but I\'ve

18条回答
  •  没有蜡笔的小新
    2020-12-29 12:50

    The problem with your first solution is that it double-counts multiples of 15 (because they are multiples of both 3 and 5).

    The problem with your second solution is that it doesn't count 999 (a multiple of 3). Just set max = 1000 to fix this.

提交回复
热议问题