Skip to content

Instantly share code, notes, and snippets.

@lzzy12
Created November 15, 2018 06:34
Show Gist options
  • Save lzzy12/d271a78926116fe4b04c6fe921c31c55 to your computer and use it in GitHub Desktop.
Save lzzy12/d271a78926116fe4b04c6fe921c31c55 to your computer and use it in GitHub Desktop.
int factorial(int x) {
if (x == 0 || x == 1)
{
return 1;
}
return (x * factorial(x - 1));
}
int hcf(int x, int y) {
if (x == y)
return x;
int small = (x < y) ? x : y, res = 1;
for (int i = 1; i <= small; i++) {
if (x % i == 0 && y % i == 0) {
res = i;
}
}
return res;
}
int lcm(int x, int y, int z) {
int lcm;
lcm = x * y / hcf(x, y);
return lcm * z / hcf(lcm, z);
}
void main() {
int x, y, z;
cin >> x >> y >> z;
x = factorial(x);
y = factorial(y);
z = factorial(z);
cout << lcm(x, y, z);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment