51nod 1012 最小公倍数LCM
2017-09-18 21:10
211 查看
1012 最小公倍数LCM
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
收藏
关注
输入2个正整数A,B,求A与B的最小公倍数。
Input
Output
Input示例
Output示例
* 求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;
}
基准时间限制: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;
}
相关文章推荐
- 51nod 1012 最小公倍数LCM
- 51Nod 1012 最小公倍数LCM
- 【51Nod】1012 最小公倍数LCM
- 51nod 1012 最小公倍数LCM
- 51Nod-1012-最小公倍数LCM
- 1012 最小公倍数LCM
- 【51NOD-0】1012 最小公倍数LCM
- 最小公倍数LCM 51Nod - 1012
- 51nod 1012 最小公倍数LCM【数论】
- 1012 最小公倍数LCM
- 51Nod-1012 最小公倍数LCM【欧几里得算法】
- 【51nod】1012 最小公倍数LCM - 辗转相除法
- 51 NOD 1012 最小公倍数LCM
- 51Nod 1012 最小公倍数LCM
- (51nod)1012 - 最小公倍数LCM
- 51Nod-1012-最小公倍数LCM
- 51nod_1012 最小公倍数LCM
- 51nod 1098 最小方差
- 51nod 1052 最大m子段和 DP
- 51nod 1119 机器人走方格 V2(费马小定理+快速幂 求逆元)