Project Euler - 5

최소공배수

1부터 20까지 숫자 모두로 나누어도 몫이 0인 가장 작은 숫자를 구하라.
"""
Smallest multiple

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
"""

if __name__ == '__main__':
num = 20
while True:
for d in range(1, 21):
if num % d != 0:
break
else:
print(num)
break
num += 20

연산 횟수를 줄이고자, 시작값을 20으로 하고, 증분도 20으로 하였다.

댓글

이 블로그의 인기 게시물

Project Euler - 3

메인 스크립트

예외 처리