Returns the smallest positive number that is evenly divisible (divisible with no remainder) by all of the numbers from 1 to n. >>> solution(10) 2520 >>> solution(15) 360360 >>> solution(22) 232792560
(n: int = 20)
| 38 | |
| 39 | |
| 40 | def solution(n: int = 20) -> int: |
| 41 | """ |
| 42 | Returns the smallest positive number that is evenly divisible (divisible |
| 43 | with no remainder) by all of the numbers from 1 to n. |
| 44 | |
| 45 | >>> solution(10) |
| 46 | 2520 |
| 47 | >>> solution(15) |
| 48 | 360360 |
| 49 | >>> solution(22) |
| 50 | 232792560 |
| 51 | """ |
| 52 | |
| 53 | g = 1 |
| 54 | for i in range(1, n + 1): |
| 55 | g = lcm(g, i) |
| 56 | return g |
| 57 | |
| 58 | |
| 59 | if __name__ == "__main__": |