FANDOM


Problem 5Edit

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 number that is evenly divisible by all of the numbers from 1 to 20?

Notes:Edit

This program is rather ugly.. but the brute force solution took over 3 minutes, and generating #tg dynamically would probably be more complicated than what I have here. This completes immediately.

CodeEdit

new number n
new number t
new number tv 20
new number cur
new number tg
set #tg 2
set #tg #tg * 3
set #tg #tg * 5
set #tg #tg * 7
set #tg #tg * 11
set #tg #tg * 13
set #tg #tg * 17
set #tg #tg * 19
set #cur #tg
hereis loop
set #n #tv
hereis iloop
if #n = 0 end
set #t #cur % #n
set #n #n - 1
if #t ! 0 eiloop
goto iloop
hereis eiloop
set #cur #cur + #tg
goto loop
hereis end
write #cur