> 其他 >
两个数的最小公倍数用算法怎么算
人气:147 ℃ 时间:2020-01-31 08:31:49
解答
int MaxAB(int a,int b)
{
if(a>b && !a%b || a==b) return a;
if(a < b && !b%a) return b;
//先求最大公约数
int nMul;
int nMinAB = (a>b)?(nMul=b,a%b):(nMul=a,b%a);
while(nMinAB)
{
int nTemp = nMinAB;
nMinAB = nMul % nMinAB;
nMul = nTemp;
}
return A*B/nMul;
}
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版