hdu1108-最小公倍数最大公约数

来源:互联网 发布:电脑网络配置怎么设置 编辑:程序博客网 时间:2024/05/22 03:52

杭电OJ1108

最小公倍数 = 最大公约数 / 两数之积

#include <iostream>using namespace std;int gcd(int a,int b){    while (a!=b)    {        if(a>b) a = a-b;        else b = b-a;    }    return a;}int main(){    int a,b;    while(cin>>a>>b)    {        cout<<a/(gcd(a,b))*b<<endl;        //先除后乘小心越界    }    return 0;}
0 0
原创粉丝点击