AOJ 0005 GCD and LCM

来源:互联网 发布:简单优化模板源码下载 编辑:程序博客网 时间:2024/06/04 17:58

辗转相除法求GCD。

#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>using namespace std;typedef long long int ll;ll GCD(ll x, ll y){    return !y ? x : GCD(y, x % y);}ll LCM(ll x, ll y){    return x * y / GCD(x, y);}int main(){    ll a, b;    while (cin >> a >> b)    {        cout << GCD(a, b) << ' ' << LCM(a, b) << endl;    }    return 0;}


0 0
原创粉丝点击