码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 2028 Lowest Common Multiple Plus

时间:2018-07-20 11:15:38      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:gcd   href   targe   its   开始   com   输入   rip   scanf   

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;
}

  

HDU 2028 Lowest Common Multiple Plus

标签:gcd   href   targe   its   开始   com   输入   rip   scanf   

原文地址:https://www.cnblogs.com/zlrrrr/p/9339633.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!