The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.







Input

Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers
in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.





Output

For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.





Sample Input

2

3 5 7 15

6 4 10296 936 1287 792 1





Sample Output

105

10296

题目的意思:有多组测试,每组有n个数,求这n个数的最小公倍数;

代码:

  1. #include <iostream>
  2. using namespace std;
  3. long long n,m,i,j,k,a;
  4. int main() {
  5. cin>>n;
  6. while(n--){
  7. cin>>m;
  8. cin>>k;m=m-1;
  9. while(m--)
  10. {
  11. cin>>a;
  12. j=k*a;
  13. while(k!=0)
  14. {
  15. i=a%k;
  16. a=k;
  17. k=i;
  18. }
  19. k=j/a;
  20. }
  21. cout<<k<<endl;
  22. }
  23. return 0;
  24. }

思想是:是求两个数的最小公倍数延伸;比如现在有三个数,a,b,c;先求出a和b的最小公倍数d;然后再求d和a的最小公倍数e;e就是a,b,c的最小公倍数;

hdu 1019 n个数的最小公倍数的更多相关文章

  1. hdu 1788(多个数的最小公倍数)

    Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 ...

  2. HDU 1019 (多个数的最小公倍数)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (J ...

  3. HDU 1019 Least Common Multiple【gcd+lcm+水+多个数的lcm】

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

  4. Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】

    Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...

  5. n个数的最小公倍数

    Description 求n个数的最小公倍数.   Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数.   Output 为每组测试数据输出它们的最小公倍数,每个测 ...

  6. HDOJ-ACM1019(JAVA) 多个数的最小公倍数

    题意:求多个数的最小公倍数 很简单,但是我一开始的做法,估计会让结果越界(超过int的最大值) import java.util.*; import java.io.*; public class M ...

  7. ACM hdu 1019 Least Common Multiple

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

  8. HDU_2028——求多个数的最小公倍数

    Problem Description 求n个数的最小公倍数.   Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数.   Output 为每组测试数据输出它们的最 ...

  9. HDU 1019 Least Common Multiple GCD

    解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...

随机推荐

  1. [BZOJ3561] DZY Loves Math VI

    (14.10.28改) 本来只想写BZOJ3739:DZY Loves Math VIII的,不过因为和VI有关系,而且也没别人写过VI的题解,那么写下. 不过我还不会插公式…… http://www ...

  2. 记录一下最近开发web移动前端的过程

    两个项目 第一个是公司网站的移动端,我所在的公司是做某方面的新闻站的. 所以说页面基本是以一条条的新闻+图文混排为主,顶部有一个自动slider+触屏滑动的功能, 使用的是swipe插件,轻量,简洁非 ...

  3. win7下安装搭建PHP环境

    由于最近新找的工作要求php,所以在电脑上安装搭建了PHP环境.主要参考了这篇文章http://www.leapsoul.cn/?p=695(之前第一次搭建时由于版本问题没有弄好) 1.先装apach ...

  4. 分享一个js生成二维码的库

    二维码用js生成会比用服务器生成方便很多,只要把window.location.href的值传入,即可生成对应的二维码..最主要是,这个库可以兼容ie6~ie9哦... 具体使用,请看官网:http: ...

  5. Python新手学习基础之循环结构练习

    有几个元音字母? 有一个字符串"I learn Python from maya",我们想要查找出它里面的元音字母(aeiou)(其实是找出这几个小写字母),并统计出其元音字符的个 ...

  6. Sphinx编译docs文档

    在使用Python.Django的过程中,经常看到docs目录,里面存放着一些txt文本文件,也就是自带的一些帮助文档,里面有make.bat,在dos目录下直接执行make,给出的帮助是可以转换成H ...

  7. NSNumber与NSInteger的区别 -bei

    基本类型,如同C 语言中的 int 类型一样,拿来就可以直接用. 而类在使用时,必须先创建一个对象,再为对象分配空间,接着做初始化和赋值. 类的初始化,需用类自身的方法 (类方法). 代码中所创建的对 ...

  8. layout_gravity与gravity的区别

    1:android:gravity 这个是针对控件里的元素来说的,用来控制元素在该控件里的显示位置. 2:android:layout_gravity 这个是针对控件本身而言,用来控制该控件在包含该控 ...

  9. 使用 ExpandableListView 实现折叠ListView

    1:layout/expandablelistview_groups.xml 标题文件 <?xml version="1.0" encoding="utf-8&qu ...

  10. 这样就算会了PHP么?-2

    学些关于函数FUNCTION方面的东东.. 感觉和PYTHON的APLLY功能差不多.. <?php function come(){ echo "来啦<p>"; ...