devLupin / algorithm

PS
1 stars 0 forks source link

최대공약수(GCD), 최소공배수(LCM) #20

Open devLupin opened 1 year ago

devLupin commented 1 year ago

GCD


int gcd(int a, int b) {
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}
devLupin commented 1 year ago

LCM


int lcm(int a, int b) {
    return (a * b) / gcd(a, b);
}