51nod 1012 最小公倍数LCM【数论】

xiaoxiao2021-02-28  112

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<stdio.h> #define LL long long LL gcd(LL a,LL b) { if(a%b==0) return b; else return gcd(b,a%b); } LL lcm(LL a,LL b) { return (a/gcd(a,b)*b);//如果是int,这样处理可以防止溢出 } int main() { LL n,m; while(scanf("%lld%lld",&n,&m)!=EOF) { printf("%lld\n",lcm(n,m)); } return 0; }
转载请注明原文地址: https://www.6miu.com/read-25008.html

最新回复(0)