`
rokuan
  • 浏览: 19624 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Project Euler每帖一题(001)

阅读更多
引用
题目:If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.


我的python解:
num_3 = 999 / 3
num_5 = 999 / 5
num_15 = 999 / 15
num = 0
for i in range(num_3):
    num += (i+1) * 3
for j in range(num_5):
    num += (j+1) * 5
for x in range(num_15):
    num -= (x+1) * 15
    
print num


如果有更好的的解法,求交流~
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics