Lowest Common Multiple Plus(数论)

来源:互联网 发布:二维动画软件 编辑:程序博客网 时间:2024/06/05 23:03
E - Lowest Common Multiple Plus
Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u
SubmitStatusPracticeHDU 2028

Description

求n个数的最小公倍数。
 

Input

输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数。
 

Output

为每组测试数据输出它们的最小公倍数,每个测试实例的输出占一行。你可以假设最后的输出是一个32位的整数。
 

Sample Input

2 4 63 2 5 7
 

Sample Output

1270 #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 上死了两次。。。
0 0
原创粉丝点击