HDU 1019 水啊~
View Code
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #include<math.h> 5 #define N 1000000 6 7 long long a[N]; 8 int gcd(int n,int m) 9 { 10 if(m == 0) 11 return n; 12 else 13 return gcd(m,n%m); 14 } 15 16 int Lcm(int a,int b) 17 { 18 return a/gcd(a,b)*b;//貌似这里有点问题,我一开始写成(a*b)/gcd(a,b)死活不过,结果钻到讨论区里把这个改了,结果过了,搞不懂! 19 } 20 21 int main() 22 { 23 int i, ncases, n; 24 long long num; 25 26 scanf("%d",&ncases); 27 while( ncases-- ) 28 { 29 scanf("%d",&n); 30 for(i = 0; i < n; i++) 31 { 32 scanf("%lld",&a[i]); 33 } 34 num = a[0]; 35 for(i = 1; i < n; i++) 36 num = Lcm(num, a[i]); 37 38 printf("%lld\n",num); 39 } 40 system("pause"); 41 return 0; 42 }