티스토리 뷰
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 |
댓글