Problem description calculates the minimum public multiple of N numbers. Input contains multiple test instances. Each test instance starts with a positive integer N and then a positive integer n. Output is the minimum public multiple of each group of test data. The output of each test instance occupies one row. Assume that the final output is a 32-bit integer. Sample input2 4 63 2 5 7 sample output1270
1 # include <stdio. h> 2 int get_lcm (int A, int B); 3 4 int main () {5 Int N; 6 int result; 7 int number; 8 9 While (scanf ("% d", & N ))! = EOF) {10 result = 1; 11 while (n --) {12 scanf ("% d", & number); 13 14 result = get_lcm (result, number ); 15} 16 17 printf ("% d \ n", result); 18} 19 Return 0; 20} 21 22 int get_lcm (int A, int B) {23 int temp; 24 int remainder; 25 int A; 26 int B; 27 28 A = A; 29 B = B; 30 31 if (a <B) {32 temp =; 33 A = B; 34 B = temp; 35} 36 37 while (a % B) {38 remainder = A % B; 39 A = B; 40 B = remainder; 41} 42 43 return a/B * B; // cannot be written as a * B/B, because it may overflow 44}
Lowest common multiple plus