HDU1019 Least Common Multiple 就是求最小公倍数

好久没有做题啦,手都快生了,最近实在很忙乎= =

1019这题题目英文出的有点看不懂,也耽误了不少时间,后来明白点,似乎就是求很多数字的的最小公倍数,这里用了一下迭代。。

 1 #include <stdio.h>
 2 
 3 int func(int a, int b){
 4     if(b == 0){
 5         return a;
 6     }
 7     return func(b, a % b);
 8 }
 9 
10 int lcm(int a, int b){
11     return a / func(a,b) * b;
12 }
13 
14 int a[100000];
15 
16 int main(){
17     int n, temp;
18     int i;
19     scanf("%d",&n);  //n组
20     while(n--){
21         int m;
22         scanf("%d",&m);
23         for(i = 0; i < m; i++){
24             scanf("%d",&a[i]);
25         }
26         temp = a[0];
27         for(i = 1; i < m; i++){
28             temp = lcm(temp, a[i]);
29         }
30         printf("%d
",temp);
31     }
32     return 0;
33 }
Everything will be ok in the end. If it is not ok then it is not the end.
原文地址:https://www.cnblogs.com/shirleytian/p/3285972.html