HDU-1019 Least Common Multiple

  注意求最小公倍数的时候先乘后除,代码如下:

#include <stdio.h>
#include <math.h>

int gcd( int a, int b )
{
    if( b== 0 )
    {
        return a;
    }
    return gcd( b, a% b );
}

int main()
{
    int T;
    scanf( "%d", &T );
    while( T-- )
    {
        int N, last, cur;
        scanf( "%d", &N );
        scanf( "%d", &last );
        for( int i= 2; i<= N; ++i )
        {
            scanf( "%d", &cur );
            last= last/ gcd( last, cur )* cur;
        }
        printf( "%d\n", last );
    }
}

  

posted @ 2011-08-08 12:15  沐阳  阅读(260)  评论(0编辑  收藏  举报