Project Euler: Problem 5

Nov 24, 2025

🚨

Spoiler alert: This post contains spoilers for Project Euler.

Problem 5

projecteuler p5 (light) Smallest positive number that is evenly divisible by all of the numbers from 1 to 20

Hand-written solution

This is a least common multiples problem. There is a straightforward formula for this that involves multiplying the highest power of each prime number <=N<= N. In this case, N=20N=20.

It's easier to do this one by hand than to write the code.

For example (skipping "11" for obvious reasons):

N=2;21=2N=2; \quad 2^{1}=2
N=3;21×31=6N=3; \quad 2^{1} \times 3^{1}=6
N=4;22×31=12N=4; \quad 2^{2} \times 3^{1}=12
N=5;22×31×51=60N=5; \quad 2^{2} \times 3^{1} \times 5^{1} = 60
N=6;22×31×51=60N=6; \quad 2^{2} \times 3^{1} \times 5^{1} = 60
N=7;22×31×51×71=420N=7; \quad 2^{2} \times 3^{1} \times 5^{1} \times 7^{1} = 420
N=8;23×31×51×71=840N=8; \quad 2^{3} \times 3^{1} \times 5^{1} \times 7^{1} = 840
N=9;23×32×51×71=2520N=9; \quad 2^{3} \times 3^{2} \times 5^{1} \times 7^{1} = 2520
â‹®\quad \vdots
N=20;24×32×51×71×111×131×171×191=232,792,560N=20; \quad 2^{4} \times 3^{2} \times 5^{1} \times 7^{1} \times 11^{1} \times 13^{1} \times 17^{1} \times 19^{1} = 232,792,560

Conclusion

A fairly straightforward problem that didn't need coding for a change.

Final answer

232,792,560232,792,560

Ryan McIntire