hdu 1019Least Common Multiple

/...................................................................................................................................................................................................................................................................................................................\

注意:x与y乘积等于x与y最小公倍数与最大公约数的乘积。

\.................................................................................................................................................................................................................................................................................................................../

#include<stdio.h>
#include <iostream>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<list>
#include<vector>
#pragma comment(linker,"/STACK:102400000,102400000")
using namespace std;
int gcd(int n,int m)//求最大公约数
{
    int t;
    while(m)
    {
       t=n%m;
       n=m;
       m=t;
       gcd(n,m);
    }
    return n;
}

int main()
 {
      int m,n,t,x,y,i;
      scanf("%d",&t);
      while(t--)
      {
          scanf("%d%d",&n,&x);
          for(i=1;i<n;i++)
          {
              scanf("%d",&y);//分步两个两个进行求解
              x=x/gcd(x,y)*y;
          }
          printf("%d\n",x);
      }
      return 0;
 }


你可能感兴趣的:(HDU)