HDOJ_1019_大二写_Least Common Multiple

思路:最小公倍数=两个数相乘除以两个数的最大公约数。

AC代码:

#include <iostream>
#include <cstdio>
using namespace std;

unsigned int gcd(unsigned int t1,unsigned int t2)
{
    if(t2==0) return (t1);
    else return gcd(t2,t1%t2);
}

int main(void)
{
    freopen("in.txt","r",stdin);
    unsigned int N;
    scanf("%ud",&N);
    while(N--)
    {
        unsigned int n,t1,t2;
        scanf("%u",&n);
        scanf("%u",&t1);
        n--;
        while(n--)
        {
            scanf("%u",&t2);
            t1=t1/gcd(t1,t2)*t2;
        }
        printf("%u\n",t1);
    }

    fclose(stdin);
    return 0;
 } 

 

posted @ 2018-11-29 06:12  pha创噬  阅读(108)  评论(0编辑  收藏  举报