以下為程式碼
#include <stdio.h>
int two_gcd(int first, int last) {
if (first > last) {
while (true) {
first %= last;
if (first == 0)
return last;
last %= first;
if (last == 0)
return first;
}
} else {
while (true) {
last %= first;
if (last == 0)
return first;
first %= last;
if (first == 0)
return last;
}
}
}
void compute_gcd(int num, int arr[]) {
long long gcd = 0;
long long lcm = arr[0];
for (int i = 1; i < num; i++) {
gcd = two_gcd(lcm, arr[i]);
lcm = (lcm * arr[i]) / gcd;
}
printf("%lld\n", lcm);
}
int main() {
int num = 0;
int arr[11] = {0};
while (scanf("%d", &num)) {
if (num == 0)
break;
for (int i = 0; i < num; i++) {
scanf("%d", &arr[i]);
}
compute_gcd(num, arr);
}
return 0;
}