Skip to content

Instantly share code, notes, and snippets.

@hhc0null
Created January 13, 2012 08:40
Show Gist options
  • Save hhc0null/1605108 to your computer and use it in GitHub Desktop.
Save hhc0null/1605108 to your computer and use it in GitHub Desktop.
aoj-0005-GCD_and_LCM.cpp
#include <iostream>
#include <iomanip>
#include <cstdio>
using namespace std;
int main(void) {
unsigned long a, b, m, n, tmp, gcd, lcm;
for(;scanf("%ld %ld", &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;
} a
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment