Skip to content

Instantly share code, notes, and snippets.

@aadimator
Created July 19, 2016 05:52
Show Gist options
  • Save aadimator/2c69790ae2d908dd78068f0d77fffde9 to your computer and use it in GitHub Desktop.
Save aadimator/2c69790ae2d908dd78068f0d77fffde9 to your computer and use it in GitHub Desktop.
Least Common Multiple
#include <iostream>
int euclidGCD (long a, long b) {
if (b == 0) return a;
return euclidGCD(b, a%b);
}
long long lcm(long long a, long long b) {
return (a * b)/euclidGCD(a, b);
}
int main() {
long long a, b;
std::cin >> a >> b;
std::cout << lcm(a, b) << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment