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.

 

InputInput 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. 
OutputFor 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<bits/stdc++.h>
using namespace std;
long long solve(long long a,long long b)
{
long long m,n,c;
m = a, n = b;
a = max(m,n);
b = min(m,n);
while(b)
{
c = a % b;
a = b;
b = c;
}
return m*n/a;
}
int main()
{
long long T,n,a,b;
while(cin>>T)
{
while(T--)
{
scanf("%d",&n);
scanf("%d",&a);
for(int i = ; i < n-; i++)
{
scanf("%d",&b);
a = solve(a,b);
}
cout<<a<<endl;
}
}
return ;
}

ACM Least Common Multiple的更多相关文章

  1. 2028 ACM Lowest Common Multiple Plus

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2028 思路:最一想到的就是暴力求解,从1开始一直到最后的答案,一直来除以给出的数列的数,直到余数为0:当然 ...

  2. ACM hdu 1019 Least Common Multiple

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

  3. ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)

    Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...

  4. HDU-1019 Least Common Multiple

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

  5. ACM-简单题之Least Common Multiple——hdu1019

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

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

  7. hdu_1019Least Common Multiple(最小公倍数)

    太简单了...题目都不想贴了 //算n个数的最小公倍数 #include<cstdio> #include<cstring> #include<algorithm> ...

  8. HDU 4913 Least common multiple

    题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...

  9. HDU 3092 Least common multiple 01背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...

随机推荐

  1. PyCharm设置仿sublime配色__Py版本2018.1

    Talk is cheap~ Let's do this! 配色效果图: 在网上搜了一大圈,没有能看的一清二楚的,注意本次Pycharm版本是2018.1,如果是别的版本,基本设置也是大同小异~ 看图 ...

  2. Dictionary导致CPU暴涨

    中午吃完饭回来,刚想眯一会,突然发现公司预警群报警,某台机器CPU100%,连续三次报警,心里咯噔一下,我新开发的程序就在这上面,是不是我的程序导致的?立马远程,oh my god,果然是. 二话不说 ...

  3. Havel-Hakimi定理---通过度数列判断是否可图化

    0.可图:一个非负整数组成的序列如果是某个无向图的度序列,则该序列是可图的. 1.度序列:Sequence Degree,若把图G所有顶点的度数排成一个序列,责成该序列为图G的一个序列.该序列可以是非 ...

  4. MySQL操作与修改表

    插入数据(insert) insert语句的3个主要组成部分: 所要插入数据的表的名称: 表终需要使用的列的名称: 需要插入到列的值. 数字型主键生成机制 数字型主键生成机制,除了随机选择数字外,还可 ...

  5. python操作MySQL数据库并将数据写入excel

    #!/usr/bin/python# -*- coding:utf-8 -*-'''方法:通过pymsql模块连接mysql数据库,然后通过游标cursor查询SQL语句将结果存储在Excel文件中, ...

  6. 树莓派控制HC-SR04超声波模块测距(新手向+C语言向)

    因为作业要求使用c语言代码,这里先附上一段摘自网上的代码 感谢KalaerSun的c语言代码,摘自https://blog.csdn.net/qq_25247589/article/details/6 ...

  7. [AHOI2005]洗牌

    题目描述 为了表彰小联为Samuel星球的探险所做出的贡献,小联被邀请参加Samuel星球近距离载人探险活动. 由于Samuel星球相当遥远,科学家们要在飞船中度过相当长的一段时间,小联提议用扑克牌打 ...

  8. [APIO2011]

    来自FallDream的博客,未经允许,请勿转载,谢谢. ------------------------------------------------------ A.[Apio2011]方格染色 ...

  9. Java面试题—初级(8)

    基本表结构:  student(sno,sname,sage,ssex)学生表        course(cno,cname,tno) 课程表        sc(sno,cno,score) 成绩 ...

  10. Cookie 和 Session的基本使用

    cookie: 放在客户端上的键值对. 1.设置cookie obj = render(request,'index.html') obj.set_cookie('key','value') retu ...