练习自己的code能力,完成projecteuler的题目,做一个归档记录。
第1题:
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.
找出1000以下,可以整除3或者5的数,并计算出它们的和。
def Multiples_of_3_and_5(num): sum = 0 for n in xrange(num): if not n%3 or not n%5: sum+=n return sum if __name__ == "__main__": print Multiples_of_3_and_5(1000)
时间: 2024-10-15 12:21:16