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. Java练习(模拟扫雷游戏)

    要为扫雷游戏布置地雷,扫雷游戏的扫雷面板可以用二维int数组表示.如某位置为地雷,则该位置用数字-1表示, 如该位置不是地雷,则暂时用数字0表示. 编写程序完成在该二维数组中随机布雷的操作,程序读入3 ...

  2. python--socket套接字/TCP

    socket套接字/TCP 一 客户端/服务器架构 C/S架构,包括 硬件C/S架构(打印机) 软件C/S 架构(web服务) C/S架构的软件(软件属于应用层)是基于网络进行通信的 Server端要 ...

  3. 教你如何用AST语法树对代码“动手脚”

    个推安卓工程师,负责公司移动端项目的架构和开发,主导移动端日志管理平台系统架构和开发工作,熟悉前后端的技术线,参与个推SDK主要业务研发工作,善于解决项目中遇到的痛点问题. 作为程序猿,每天都在写代码 ...

  4. iframe 里的高度自适应

    由于公司里的很多东西都要用到iframe 导致我不得不各种百度 首先是自适应高度 // document.domain = "caibaojian.com"; function s ...

  5. p2p项目总结

    1.关于ajax请求所要注意的地方:$.psot(url,json,callback,type) (1)url路径问题,在html中写绝对路径不能用EL表达式,EL表达式只能在jsp中使用 (2)js ...

  6. spring源码阅读(1)bean解析

    public class Test { public static void main(String[] args) throws Exception { BeanFactory beanFactor ...

  7. [HNOI2011]数学作业

    题目描述 小 C 数学成绩优异,于是老师给小 C 留了一道非常难的数学作业题: 给定正整数 N 和 M,要求计算 Concatenate (1 .. N) Mod M 的值,其中 Concatenat ...

  8. ●POJ 1259 The Picnic

    题链: http://poj.org/problem?id=1259 题解: 计算几何,凸包,DP 题意:给出N($N\leq100$)个点,求出最大的凸包使得凸包里面不存在点(边上可以有).输出最大 ...

  9. spring boot新建项目启动报:Unregistering JMX-exposed beans on shutdown

    原因为:SpringBoot内置Tomcat没有正常启动,在pom.xml 中添加: <dependency> <groupId>org.springframework.boo ...

  10. Python【第二课】 字符串,列表,字典,集合,文件操作

    本篇内容 字符串操作 列表,元组操作 字典操作 集合操作 文件操作 其他 1.字符串操作 1.1 字符串定义 特性:不可修改 字符串是 Python 中最常用的数据类型.我们可以使用引号('或&quo ...