Answers for "gcd and lcm in c++"

C++
2

gcd and lcm in c++

long long gcd(long long int a, long long int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
long long lcm(ll int a, ll int b)
{
    return (a / gcd(a, b)) * b;
}
// there is a math formula used in this code which you can search up about,
// but you can just use it as it is.
Posted by: Guest on April-29-2022

Browse Popular Code Answers by Language