hdu 2028 Lowest Common Multiple Plus

http://acm.hdu.edu.cn/showproblem.php?pid=2028

深夜十二点水的题,第一次wa,不过后来看看很简单,gcd求最大公约数,然后每次求出最小公倍数。。。最后知道用该数除以最大公约数再乘以本身就可以了

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

int gcd(int a,int b)

{

    return b==0?a:gcd(b,a%b);

}

int main()

{

    int n,a,b,k;

    while(scanf("%d",&n)!=EOF)

    {

          scanf("%d",&b);

          for(int i=1;i<n;++i)

          {

                  scanf("%d",&a);

                  k=gcd(b,a);

                  b=b/k*a;

          }

          printf("%d\n",b);

    }

    //system("pause");

    return 0;

}

posted @ 2011-08-03 15:59  ○o尐懶錨o  阅读(1318)  评论(0编辑  收藏  举报