One efficient way to solve this problem is by finding the prime factors for each number from 1 to 20, then multiplying the highest power of each prime factor together to get the solution. Here's an implementation in Python:
main.py504 chars16 lines
This function takes an input n
and returns the smallest positive number that is evenly divisible by all numbers from 1 to n
. Here's how to use it:
main.py67 chars5 lines
The first call finds the smallest multiple of all numbers from 1 to 10, which is 2520. The second call finds the smallest multiple of all numbers from 1 to 20, which is 232792560.
gistlibby LogSnag