E - Lowest Common Multiple Plus
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
求n个数的最小公倍数。
Input
输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
Output
为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
Sample Input
2 4 6 3 2 5 7
Sample Output
12 70 #include <iostream> #include <cstdio> using namespace std; long long gcd(long long a, long long b) { return b == 0? a : gcd(b, a % b); } int main() { long long t, i, lcm; while( cin >> t ) { int a[t]; for( i=0; i<t; i++ ) cin >> a[i]; if( 1 == t ) cout << a[0] << endl; else { for( i=0; i<t; i++ ) { if( i<2 ) { lcm = a[i]*a[i+1]/gcd(a[i],a[i+1]); i++; } else { lcm = lcm*a[i]/gcd(a[i],lcm); } } cout << lcm << endl; } } return 0; } 在long long 上死了两次。。。