题解 | #求最小公倍数#

求最小公倍数

http://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int c = min(a,b);
    int res;
    for(int i = 1;i<=c;i++)
    {
        res = i * max(a,b);//最小公倍数一定是大数的倍数
        if(res % a ==0 && res % b == 0)break;
    }
    cout<<res<<endl;
    return 0;
    
    
}
全部评论

相关推荐

05-12 16:04
已编辑
江西财经大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务