Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Created January 13, 2012 10:53
Show Gist options
  • Save hhc0null/1605525 to your computer and use it in GitHub Desktop.
Save hhc0null/1605525 to your computer and use it in GitHub Desktop.
aoj-0005-GCD_and_LCM-ans.cpp
#include <iostream>
#include <iomanip>
#include <cstdio>
using namespace std;
int main(void) {
long long int a, b, m, n, tmp, gcd, lcm;
for(;scanf("%lld %lld", &a, &b) == 2;) {
m = a;
n = b;
if(m < n) {
tmp = b;
b = a;
a = tmp;
}
while(n) {
tmp = n;
n = m % n;
m = tmp;
}
gcd = m;
lcm = (a * b) / gcd;
cout << gcd << " " << lcm << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment