寻找最大公约数方法
代码如下:
1 int gcd (int a, int b) { 2 return b ? gcd (b, a % b) : a; 3 }
应用:求最小公倍数
1 int lcm (int a, int b) { 2 return a / gcd (a, b) * b; 3 }