现在的位置: 首页 > 综合 > 正文

HDU-1019 Least Common Multiple

2013年02月02日 ⁄ 综合 ⁄ 共 289字 ⁄ 字号 评论关闭

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

#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 );
    }
}

  

抱歉!评论已关闭.