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
测试样例:
input
22671 278464
output
27567936
分析:
最小公倍数=两整数的乘积÷最大公约数
我刚开始的代码是这样的
#include<iostream> #include<cstring> using namespace std; int gcd(int x,int y) { int t; while(y > 0) { t = x % y; x = y; y = t; } return x; } int main() { int a,b; cin >> a >> b; cout << a * b/gcd(a,b); return 0; }
但是一直WA
然后发现原来超了范围,o(╥﹏╥)o
改成 long long 就A了
给自己长个记性吧,