欧几里得方法:只要两数不相等,就反复用大数减去小数,直到相等为止
#include <iostream>
#include <time.h>
using namespace std;
int argc(int x,int y)
{
while ( x != y )
{
if( x > y )
x= x- y;
else
y =y - x;
}
return x;
}
int main()
{
int x,y;
while (1)
{
cin >> x >> y;
cout << argc( x , y ) <<endl;
}
system("pause");
return 0;
}
//最小公倍数
int main()
{
int x,y;
while (1)
{
cin >> x >> y;
cout << x / argc( x , y ) * y <<endl;
}
system("pause");
return 0;
}