题解 | #求最小公倍数#

求最小公倍数

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


using namespace std;

set<int> y(int n)
{
    set<int> res;
    for(int i=1;i<=n;i++)
    {
        if(n%i==0)
        {
            res.insert(i);
        }
    }
    
    return res;
}

int main()
{
    int A,B;
    while(cin>>A>>B)
    {
        set<int> set_A=y(A);
        set<int> set_B=y(B);
        
        int tmp=0;
        for(auto it=set_A.begin();it!=set_A.end();it++)
        {
            if(set_B.find(*it)!=set_B.end())
            {
                if(*it>tmp)
                {
                    tmp=*it;
                }
            }
        }
        cout<<A*B/tmp<<endl;
    }
    return 0;
}
全部评论

相关推荐

10-10 16:30
济宁学院 Java
不想做程序员:面试官:蓝桥杯三等奖?你多去两次厕所都能拿二等吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务