Solution for Problem 5 - dhermes/project-euler GitHub Wiki

Problem Statement

Project Euler Problem 5: 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?

Solution

Using the fact that lcm_(a, b) gcd(a, b) = ab, by using the Euclidean algorithm to compute gcd this problem is easy to attack. Defining s(n) as the smallest number divisible by 1 to n, we have s(n) = lcm(s(n - 1), n) with s(1) = 1.

Links

Previous