【HDOJ】1019 Least Common Multiple
gcd总是忘记,留存。
1 #include <stdio.h> 2 3 int gcd(int a, int b) { 4 int r; 5 6 if (a<b) { 7 r = b; 8 b = a; 9 a = r; 10 } 11 12 while (b) { 13 r = a % b; 14 a = b; 15 b = r; 16 } 17 18 return a; 19 } 20 21 int main() { 22 int n, case_n; 23 int i, a, b, tmp; 24 25 scanf("%d", &case_n); 26 27 while (case_n--) { 28 scanf("%d %d", &n, &a); 29 for (i=1; i<n; ++i) { 30 scanf("%d", &b); 31 tmp = gcd(a, b); 32 a = a / tmp * b; 33 } 34 printf("%d\n", a); 35 } 36 37 return 0; 38 }