Project Euler 5
Project Euler 5
题目
Smallest multiple
$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$?
解决方案
根据定义,所求的值为$1\sim20$中间的所有数的最小公倍数$\text{lcm}$。
求多个数的$\text{lcm}$和求多个数的最大公因数$\gcd$做法一样,都是两两按顺序求。
使用了gmpy2库中的lcm方法,以后将封装到tools工具包中。
代码
1 | from gmpy2 import lcm |