&& lcm least common multiple of the greatest common divisor gcd

  • Greatest common divisor

ll gcd(ll x, ll y) {
    while (y) {
        ll tmp = y;
        y = x % y;
        x = tmp;
    }
    return x;
}
  • The least common multiple

ll lcm(ll x, ll y) {
    return x * y / gcd(x, y);
}
  • Simplifying fractions

---- divided by the greatest common divisor is the simplest denominator

y = y / gcd(x, y);
  • gcd of several formulas

    • gcd(a, b) = gcd(a - b, b)
    • gcd(x^a−1, xb−1)=xgcd(a,b)−1
    • gcd(Fib(a),Fib(b))=Fib(gcd(a,b))
Published 22 original articles · won praise 0 · Views 493

Guess you like

Origin blog.csdn.net/skyyemperor/article/details/104728192