hdu 1019(gcd & lcm)

//数论,gcd & lcm相关
//该题有只有一个数据的测试组
#include <cstdio>
#include <iostream>

int gcd(int a, int b) {
return b ? gcd(b, a%b) : a;
}

int lcm(int a, int b) {
return a / gcd(a, b) * b;
}

int main() {
int t;
scanf ("%d", &t);
while (t--) {
int n, a, b, i;
scanf ("%d%d", &n, &b);
a = 1;
a = lcm(a, b);
for (i=1; i<n; ++i) {
scanf ("%d", &b);
a = lcm(a, b);
}
printf ("%d\n", a);
}
return 0;
}

 

你可能感兴趣的:(HDU)