题目地址:
http://coder.buct.edu.cn/oj/Problem.aspx?pid=1216
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <iostream> using namespace std; __int64 gcd(__int64 a, __int64 b) { if(a<b) { a ^= b; b ^= a; a ^= b; } if(b == 0) return a; return gcd(b, a%b); } int main() { int nCases, nNum; scanf("%d", &nCases); while(nCases--) { __int64 res=1, tmp; scanf("%d", &nNum); for(int i=0; i<nNum; ++i) { scanf("%I64d", &tmp); res = res*tmp/gcd(tmp, res); } if(res > 1000000000) printf("More than a billion.\n"); else printf("%I64d\n", res); } return 0; } |