hdu1019 Least Common Multiple

 1 #include <algorithm>
 2 #include <cstdio>
 3 #include <cmath>
 4 using namespace std;
 5 int gcd(int a,int b){// a-15 b-6
 6     int c=1,t;
 7     if(a<b)        {t=a,a=b,b=t;}
 8     while(c!=0){
 9         c=a%b;
10         a=b;
11         b=c;
12     }
13     return a;
14 }
15 int main(){
16     int t,i,j,n;
17     int temp,res;
18     while(~scanf("%d",&t)){
19         while(t--){
20             scanf("%d",&n);
21             scanf("%d",&res);
22             n--;
23             while(n--){
24                 scanf("%d",&temp);
25                 res=temp/( gcd(temp,res) )*res;
26             }
27             printf("%d
",res);
28         }
29     }
30     return 0;
31 }
32         
原文地址:https://www.cnblogs.com/symons1992/p/3330730.html