Smallest multiple
No. 80
Q: |
2520 is the smallest number that can be divided by each of the numbers from 2 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? TipThe remainder operator “%”
allows for testing whether a given integer value Increment an integer candidate in a loop till the desired condition is being fulfilled. |
A: |
We propose the following solution:
The assignment
This is fully equivalent to the more explicit code:
Executing this code results in 232792560 for the smallest desired value. |
No. 81
Smallest multiple, purely algebraic solution
Q: |
Solving the previous exercise by a program is quite a no-brainer (from an experienced software developer's point of view). Provide a different solution purely based on algebraic considerations. In other words: Solve the exercice using paper and pencil only. TipConsider the underlying prime factors of all values from [2, 3, ...20]. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
A: |
We decompose each value within [2, 3, ...20] into its prime factors:
As expected we find an identical value for the desired smallest integer value of 2*2*2*2*3*3*5*7*11*13*17*19 = 232792560 which is the least common multiple of [2, 3, ...20]. |