HDU 2028 Lowest Common Multiple Plus

http://acm.hdu.edu.cn/showproblem.php?pid=2028

 

Problem Description
求n个数的最小公倍数。
 

 

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

 

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

 

Sample Input
2 4 6
3 2 5 7
 

 

Sample Output
12
70
 
代码:
#include <bits/stdc++.h>

using namespace std;

const int maxn=1e5+10;
int a[maxn];

long long int gcd(long long int a,long long int b)
{
    long long int c = a%b;
    while(c)
    {
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        long long int asd=1;
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            asd=asd*a[i]/gcd(asd,a[i]);
        }
        printf("%lld\n",asd);
    }
    return 0;
}

  

posted @ 2018-07-20 08:56  丧心病狂工科女  阅读(115)  评论(0编辑  收藏  举报