今天看到一个简洁的写法,感觉很舒服,分享一下。

int gcd(int x, int y)
{
    return y ? gcd(y, x % y) : x;
}
int lcm(int x, int y)
{
    return (x / gcd(x, y))*y;
}