HDU 1108(最小公倍数)

来源:互联网 发布:unity3d 模型形状mask 编辑:程序博客网 时间:2024/05/21 11:17


题意:如题。

#include <iostream>#include <vector>using namespace std;int dd(int x, int y);void main(){            vector<vector<int> > tmpbox;    unsigned int a;    unsigned int b;        while (cin >> a >> b)    {                if (a > 1000 || b > 1000)            continue;        vector<int> _tmp;        _tmp.push_back(a);        _tmp.push_back(b);        tmpbox.push_back(_tmp);    }    for (vector<vector<int> >::iterator it = tmpbox.begin(); it != tmpbox.end(); ++it)    {        int ntmp = dd((*it)[0], (*it)[1]);        cout << (*it)[0] / ntmp * (*it)[1] << endl;    }}int dd(int x, int y){    if(x < y)    {        x = x ^ y;         y = x ^ y;         x = x ^ y;     }    while(y != 0)    {        x = x % y;        x = x ^ y;         y = x ^ y;         x = x ^ y;     }    return x;}


 

#include <iostream>using namespace std;long gcd(long m, long n){while (n != 0){long rem = m % n;m= n;n=rem;}return m;}#define change(m, n) m=m^n,n=m^n,m=m^nvoid main(){long m, n;while (cin >> m>> n){if (n>m)change(m, n);cout << m/gcd(m,n)*n<<endl;}}

 

0 0
原创粉丝点击