杭电1019-Least Common Multiple

#include<stdio.h>
int gcd(int a,int b);
int main()
{
    int n,m,a,b,i,sum;//sum是最小公倍数
    scanf("%d",&n);
       while(n--)
       {
              scanf("%d",&m);
              sum=1;//sum=1
              for(i=1;i<=m;i++)
              {
                scanf("%d",&b);
                sum=sum/gcd(sum,b)*b;
               }
               printf("%d\n",sum);
       }
     return 0;
}
int gcd(int a,int b)
{
    int temp;
    while(a%b)
    {
      temp=b;
      b=a%b;
      a=temp;  
    }
    return b;
}

你可能感兴趣的:(杭电1019-Least Common Multiple)