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

题解:

利用一个数与另一个数的乘积等于这两个数的最小公倍数×最大公约数

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main()
{
int n,m;
cin>>n;
long long int k;
for(int t=0;t<n;t++)
{
scanf("%d",&m);
long long int cnt=1;
for(int j=0;j<m;j++)
{
scanf("%d",&k);
cnt=cnt*k/(__gcd(cnt,k));
}
printf("%lld\n",cnt);
}
return 0;
}

HDU - 1019-Least Common Multiple(求最小公倍数(gcd))的更多相关文章

  1. 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 ...

  2. HDU 1019 Least Common Multiple GCD

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

  3. ACM hdu 1019 Least Common Multiple

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

  4. HDU 1019 Least Common Multiple 数学题解

    求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...

  5. HDU - 1019 - Least Common Multiple - 质因数分解

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...

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

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

  7. 背包系列练习及总结(hud 2602 && hdu 2844 Coins && hdu 2159 && poj 1170 Shopping Offers && hdu 3092 Least common multiple && poj 1015 Jury Compromise)

    作为一个oier,以及大学acm党背包是必不可少的一部分.好久没做背包类动规了.久违地练习下-.- dd__engi的背包九讲:http://love-oriented.com/pack/ 鸣谢htt ...

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

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

  9. HDOJ 1019 Least Common Multiple(最小公倍数问题)

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

随机推荐

  1. Android SP的具体内容

    过了这么久了,看看自己的园龄都17天了,一直在总结,从未缺席,我还是很开心的,踏踏实实的完成自己能学到的. 今天学习SP SP:全称SharedPreferences,别问我为啥知道,因为打了好多遍了 ...

  2. “随手记”APP与已经发布的记账软件“鲨鱼记账”的差距

    我们使用并观察了“鲨鱼记账”APP,发现,我们的软件真的还有很多不足的地方.就功能这方面来说:“鲨鱼记账”APP有更多的收入.支出分类:就界面来说:“鲨鱼记账”APP有比我们优美太多的页面和背景.但是 ...

  3. 5、Java 修饰符

    引言:Java的修饰符根据修饰的对象不同,分为类修饰符.方法修饰符.变量修饰符,其中每种修饰符又分为访问控制修饰符和非访问控制修饰符. 1.访问控制修饰符的总结 四个关键字:public.protec ...

  4. 内网 Maven 编译

    内网 Maven 编译 有个特殊的需求,在不联网的情况下编译 Java 项目. 想到两种方案: 搭建 Nexus 私有镜像仓库. 直接把依赖 jar包 放在编译机的 maven 本地库中. 步骤简述 ...

  5. ECS7天实践进阶训练营Day1:使用阿里云ECS,快速搭建、管理VuePress静态网站

    一.概述 VuePress是2018年由尤雨溪发布的一个全新的基于Vue的静态网站生成器,它是一个非常轻量级的静态网站生成器.VuePress主要用于生成技术文档,其类似于Gitbook,我们可以用于 ...

  6. git使用-克隆仓库

    1.git clone 克隆地址 克隆地址: 2.克隆命令

  7. OGG复制进程延迟高,优化方法一(使用索引)

    日常运维过程中,可能发现OGG同步进程延迟很高: 本篇介绍其中的一种方式. OGG复制进程,或者说同步进程及通过解析ogg trail文件,输出dml语句,在目标库执行dml操作,那么延迟高可能性其一 ...

  8. windows10永久激活工具 新版win10激活工具(绝对有效的永久激活工具)

    来看这篇文章的,都用过KMS了吧?对!KMS是批量激活的,激活时间是一年,如果给女神激活,此法首选呀!!!但是帮基友激活,过了一年又来找自己,作为程序员的你,脸上是不是有点挂不住然后又不想花钱去买某宝 ...

  9. Spring中眼花缭乱的BeanDefinition

    本篇博客主要参考:Spring官网阅读(四)BeanDefinition(上) 引入主题 为什么要读Spring源码,有的人为了学习Spring中的先进思想,也有的人是为了更好的理解设计模式,当然也有 ...

  10. 简单解析PAT、PMT的程序

    刚开始学习有关TS.PAT.PMT方面的内容,参考了别人的一些程序,然后写了一个简单的解析TS的小程序.如果有地方错误,请发邮件给我843036544@qq.com. #include<stdi ...