Created
January 13, 2012 10:53
-
-
Save hhc0null/1605525 to your computer and use it in GitHub Desktop.
aoj-0005-GCD_and_LCM-ans.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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