JOJ1062: Computer Versus Mankind

来源:互联网 发布:想在淘宝买情趣用品 编辑:程序博客网 时间:2024/06/05 05:04

原题地址:http://acm.jlu.edu.cn/joj/showproblem.php?pid=1062

是求最小公倍数和最大公约数的问题

#include <iostream>

using namespace std;

int gcd(int a,int b)
{   
    while(a != b)
    {
        if(a > b)
          a -= b;
        else
          b -= a;         
    }
    return a;
   
}

int main()
{
    int a,b,c,d;
    while(cin>>a>>b && !(a==0 && b==0))
    {
        c = gcd(a,b);
        d = a * b / c;
        cout<<c<<" "<<d<<endl;
       
    }
    system("PAUSE");
   
}