Smallest number that is evenly divisible by all of the numbers from 1 to 20?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
The smallest number evenly divisible by every integer from 1 to 20 is the least common multiple, or LCM, of that range. The cleanest way to find it is to keep the highest power of every prime needed by any number in the set.
Solve it with prime factors
To build the LCM, list the prime powers that matter most:
- '
2^4from16' - '
3^2from9' - '
5from5' - '
7from7' - '
11from11' - '
13from13' - '
17from17' - '
19from19'
Now multiply them:
That number contains enough factors to be divisible by every number from 1 through 20.
Why this works
An LCM must include every prime factor needed by every number in the set. For example:
- '
8requires2^3' - '
16requires2^4'
If the final number only had 2^3, it would be divisible by 8 but not by 16. So you keep the highest required power, not every duplicate from every number.
The same logic applies to 3^2 because 9 and 18 need two factors of 3.
Verify it with code
A short Python program can confirm the answer:
Every line should print True.
You can also compute the answer programmatically using the LCM relation:
- '
lcm(a, b) = abs(a * b) // gcd(a, b)'
This prints:
That approach is often better in software because it generalizes easily to any range.
A useful way to think about the problem
This is not really a "guess the magic number" puzzle. It is an LCM problem disguised as a divisibility question. Once you recognize that, the structure becomes simple:
- find the primes involved,
- keep the largest needed power of each,
- multiply those powers.
This method works not only for 1 through 20, but for any list of positive integers. It also explains why the answer is much smaller than the raw product of all numbers in the range: the LCM keeps only the factors that are actually necessary.
A nice side effect of the prime-factor method is that it gives you both the number and the proof of minimality. Once every required prime power is present exactly once, removing any one factor would immediately break divisibility for at least one number in the range.
Common Pitfalls
The biggest mistake is multiplying all the numbers from 1 to 20 together. That produces a number divisible by everything in the range, but it is far from the smallest one.
Another common issue is forgetting that repeated prime powers matter. If you include 2 only once, the final number will fail divisibility tests for numbers such as 4, 8, and 16.
Be careful when verifying with code too. Testing only a few divisors such as 2, 5, and 10 is not enough. The answer must divide evenly by all numbers in the full range.
Finally, if you compute LCM iteratively in code, use gcd to control growth. Repeated raw multiplication becomes unnecessarily large very quickly.
Summary
- The problem is asking for the LCM of the integers from
1to20. - Keep the highest required power of each prime.
- The final answer is
232792560. - Prime factorization explains why the answer is minimal.
- In code, iterative
gcdandlcmfunctions are the cleanest general solution.

