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
'Device & Language > Python' 카테고리의 다른 글
python eulerproject 6th : Sum square difference (0) | 2017.08.24 |
---|---|
python eulerproject 5th : Smallest multiple (0) | 2017.08.16 |
python eulerproject 4th : Largest palindrome product (0) | 2017.08.16 |
python eulerproject 3rd : Largest prime factor (0) | 2017.04.06 |
python eulerproject 2nd (0) | 2014.12.27 |