HDU 1019 LCM 求最小公倍数

#include<stdio.h>
#include<cstdlib>
#include <iostream>
using namespace
std;
int
GCD(int x,int y)
{

    if
(!x || !y)return x>y?x:y;
    for
(int t;t=x%y;x=y,y=t);
    return
y;
}

int
LCM(int x,int y)
{

    int
gcd=GCD(x,y);
    return
x/gcd*y;
}

int
ans;
int
main()
{

    setbuf(stdout,NULL);
    int
T,number,i,inter;
    scanf("%d",&T);
    while
(T--)
    {

        ans=1;
        scanf("%d",&number);
        for
(i=1;i<=number;i++)
        {

            scanf("%d",&inter);
            ans=LCM(ans,inter);
        }

        printf("%d\n",ans);
    }

    return
0;
}

posted on 2011-07-25 10:54  lonelycatcher  阅读(241)  评论(0编辑  收藏  举报

导航