Compute the greatest common divisor and least common multiple of a set of integers.
辗转相除法求最大公约数,再求最小公倍数。
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Euclidean algorithm | gcd(a,b) = gcd(b, a mod b) until the remainder is 0 | Euclid, Elements, c. 300 BC |
| GCD×LCM identity | gcd(a,b) × lcm(a,b) = a × b for two numbers | Standard number-theory identity |
| Algorithm complexity | Worst case O(log min(a,b)); slowest on consecutive Fibonacci numbers (Lamé) | Lamé's theorem 1844 |
| Extensions | Extended Euclid solves ax+by=gcd for modular inverses and RSA | Number-theory / crypto foundation |
最大公约数(GCD)为两整数公有最大因子;最小公倍数(LCM)为最小公共倍数。满足 GCD(a,b)·LCM(a,b)=|a·b|。
约分、通分、周期对齐、模运算等。常用欧几里得算法(辗转相除)高效求解。