티스토리 뷰

Programming/Python

[Project Euler] 001. 3과 5의 배수

Dennis Ritchie 2018. 4. 17. 14:22

1. 문제


<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.



<3과 5의 배수>


10 미만의 3 혹은 5의 배수를 모두 나열하면 3, 5, 6, 9이고, 이 배수들의 합은 23입니다.


1000 미만의 3 혹은 5의 배수들의 합을 구하세요.


2. 풀이


풀이라 할만한 게 있나 싶네요. 간단한 코드로 해결할 수 있습니다.

sum = 0

for i in range(3, 1000):
    if i % 3 == 0 or i % 5 == 0:
        sum += i

print(sum)


'Programming > Python' 카테고리의 다른 글

[Project Euler] 002. 짝수인 피보나치 수  (0) 2018.04.17
Python에 대해  (0) 2018.04.17
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함