Problem Description

求n个数的最小公倍数。

Input

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

Output

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

Sample Input

2 4 6

3 2 5 7

Sample Output

12

70


注意:用gcd求最小公倍数是,若两个数相乘后再除以最大公约数,可能会导致数据超限,从而wa,因此应改变一下运算的顺序

#include<stdio.h>
int gcd(int x,int y)
{
return y==0?x:gcd(y,x%y);
}
int bei(int x,int y)
{
//return x*y/gcd(x,y);**此方法计算会导致数据超限**
return (x/gcd(x,y))*y;
}
int main()
{
int n,x,y=1;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
y=bei(x,y);
}
printf("%d\n",y);
y=1;
}
return 0;
}

HDU2028:Lowest Common Multiple Plus的更多相关文章

  1. 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)

    也称欧几里得算法 原理: gcd(a,b)=gcd(b,a mod b) 边界条件为 gcd(a,0)=a; 其中mod 为求余 故辗转相除法可简单的表示为: int gcd(int a, int b ...

  2. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. Lowest Common Multiple Plus

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

  4. 【九度OJ】题目1439:Least Common Multiple 解题报告

    [九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 ...

  5. leetcode:Lowest Common Ancestor of a Binary Search Tree

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  6. 题目1439:Least Common Multiple(求m个正数的最小公倍数lcm)

    题目链接:http://ac.jobdu.com/problem.php?pid=1439 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  7. LeetCode OJ:Lowest Common Ancestor of a Binary Tree(最近公共祖先)

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  8. LeetCode OJ:Lowest Common Ancestor of a Binary Search Tree(最浅的公共祖先)

    Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BS ...

  9. ACM1019:Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

随机推荐

  1. NSIS笔记

    1.IfFileExists IfFileExists D:\SA\test\testdirectory\*.* 0 +1 判断testdirectory是否是一个目录,若是,则执行接下来的第一行代码 ...

  2. POJ 2373 Dividing the Path(DP + 单调队列)

    POJ 2373 Dividing the Path 描述 农夫约翰的牛发现,在他的田里沿着山脊生长的三叶草是特别好的.为了给三叶草浇水,农夫约翰在山脊上安装了喷水器. 为了使安装更容易,每个喷头必须 ...

  3. jsp中的JSTL与EL表达式用法及区别

    对于JSTL和EL之间的关系,这个问题对于初学JSP的朋友来说,估计是个问题,下面来详细介绍一下JSTL和EL表达式他们之间的关系,以及JSTL和EL一些相关概念! EL相关概念 JSTL一般要配合E ...

  4. Win10系列:WinJS库控件

    在介绍了如何使用标准的HTML控件以及WinJS库中提供的新控件之后,下面来着重介绍WinJS库中几种常用的控件. (1)ListView控件 在开发Windows应用商店应用时可以使用ListVie ...

  5. learning ddr mode register MR2

  6. day6-if,while,for的快速掌握

    python的缩进和冒号 python之所以如此简单,归功于它的缩进机制,严格的缩进机制是的代码非常整齐规范,赏心悦目,提高了可读性,在一定意义上提高了可维护性,但对于从其他语音转过来的朋友如:jav ...

  7. java①

    1.MyEclipse Eclipse Idea 等 都是 开发java的IDE工具! 2.面试题: JDK: java开发工具包!(Java Development TooKit)! 是整个java ...

  8. 5.8 C++重载自增与自减操作符

    参考:http://www.weixueyuan.net/view/6386.html 注意: 自增“++”与自减“--”都是一元操作符,其前置和后置两种形式都可以被重载. 前置 stopwatch ...

  9. μC/OS-II在Microblaze上的移植与使用专题--“安富利杯”赛灵思FPGA设计技巧与应用创新博文大赛参赛作品

    reference:http://xilinx.eetrend.com/d6-xilinx/blog/2010-05/682.html   随着集成电路设计与制造技术的发展,FPGA芯片的容量越来越大 ...

  10. HTML 表单中的验证

    凡要验证格式的元素均需绑定datatype属性,datatype可选值内置有10类,用来指定不同的验证格式. 如果还不能满足您的验证需求,可以传入自定义datatype,自定义datatype是一个非 ...