샤브의 블로그 RSS 태그 관리 글쓰기 방명록
2014-12-23 21:11:35

Problem : Multiples of 3 and 5
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.

Answer
s=0
for x in range(0, 100):
if (x % 3)==0 :
s = s+x
elif (x %5)==0:
s = s+x
print (s)

Other
sum([x for x in range(1000) if x % 3== 0 or x % 5== 0])

출처 : https://projecteuler.net/problem=1