ll lcm(ll m, ll n)
{
ll g = __gcd(m, n);
return (m / g) * n;
}
r -= b / (lcm(x, y));
這裡有個呼叫 lcm 時,如果 x, y 太大又互質時會 overflow
可以改個地方避開這個問題
ll lcm(ll m, ll n, ll y)
{
ll g = __gcd(m, n);
ll mg = m / g;
if (y / n < mg) return y + 1;
return (m / g) * n;
}
r -= b / (lcm(x, y, b));