Chinaunix首页 | 论坛 | 博客
  • 博客访问: 12274
  • 博文数量: 8
  • 博客积分: 280
  • 博客等级: 二等列兵
  • 技术积分: 90
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-05 22:44
文章分类

全部博文(8)

文章存档

2011年(1)

2009年(7)

我的朋友
最近访客

分类: C/C++

2009-05-05 22:51:54

Least Common Multiple

Problem :     Judge Status : Accepted
RunId : 821180    Language : C++    Author :

Problem Description:

Codes:

#include
using namespace
std;
int
LCM(long int a,long int b)
{

    long int
temp1=a;
    long int
temp2=b;
    while
(temp2!=0)
    {

        long int
temp=temp1%temp2;
        temp1=temp2;
        temp2=temp;
    }

    return
a/temp1*b;
}

int
main()
{

    int
N,i,num;
    long int
a,b;
    while
(cin>>num)
    {

                   while
(cin>>N)
    {

        cin>>a;
        for
(i=0;i<N-1;i++)
        {

            cin>>b;
            a=LCM(a,b);
        }

        cout<<a<<endl;
    }
}

    return
0;
}

阅读(443) | 评论(3) | 转发(0) |
0

上一篇:没有了

下一篇:1019

给主人留下些什么吧!~~

chinaunix网友2010-05-19 22:06:14

评论里那个代码,不如博主的代码耐读 尤其是博主LCM()的return a/temp1*b;相见恨晚啊~~

chinaunix网友2009-05-05 23:08:04

你那个代码和我的有差吗?我还以为出了欧几里德还有什么新的算法类!靠, 原来是耍我的...虽然不是很赞同动不动就贴代码,不过我想这题也没怎么有人看的,你注意点,下次不要再耍我了哦! 还有你的函数写的...怎么每次进去都long一个阿?浪费空间啊?

jesff2009-05-05 23:04:44

#include using namespace std; __int64 Euclidean (__int64 a, __int64 b) { __int64 mul, tem; if(a