您的位置:首页 > 其它

51nod 1012 最小公倍数LCM

2017-09-18 21:10 211 查看
1012 最小公倍数LCM


基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题


 收藏


 关注

输入2个正整数A,B,求A与B的最小公倍数。

Input
2个数A,B,中间用空格隔开。(1<= A,B <= 10^9)


Output
输出A与B的最小公倍数。


Input示例
30 105


Output示例
210


#include<iostream>
using namespace std;

typedef long long ll;
ll gcd(ll m,ll n)
{
return (m==0)?n:gcd(n%m,m);
}

ll lcm(ll a,ll b)
{
return (a/gcd(a,b)*b);
}
int main()
{
int a,b;
cin>>a>>b;
cout<<lcm(a,b)<<end
e532
l;
return 0;
}

扩展欧几里得

/*
* 求x,y使得gcd(a, b) = a * x + b * y;
*/
int extgcd(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}

int d = extgcd(b, a % b, x, y);
int t = x;
x = y;
y = t - a / b * y;

return d;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: