본문으로 건너뛰기

프로젝트 오일러 Level 1

1 1000보다 작은 자연수 중에서 3 또는 5의 배수를 모두 더하면?

10보다 작은 자연수 중에서 3 또는 5의 배수는 3, 5, 6, 9 이고, 이것을 모두 더하면 23입니다. 1000보다 작은 자연수 중에서 3 또는 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. [overview]

def sum_multiple(d, limit):
n = (limit - 1) // d
return n * ((n + 1) * d) / 2

limit = 1000
print(sum_multiple(3, limit) + sum_multiple(5, limit) - sum_multiple(3 * 5, limit))


영어 / 한글