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. [洛谷P1198/BZOJ1012][JSOI2008] 最大数 - 树状数组/线段树?

    其实已经学了树状数组和线段树,然而懒得做题,所以至今没写多少博客 Description 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数 ...

  2. Java-Maven(五):Eclipse&Maven下创建java工程&web工程

    本章文章主要学习集成了maven插件的eclipse下,创建java project和web project的步骤. 创建java工程  第一步:使用使用maven project来创建java pr ...

  3. 关于Java中的Null

    什么是Java中的Null? null在Java中是一个非常重要的概念,它最初是为了表示缺少某些东西,例如缺少用户.资源或任何东西而发明出来的.但是这也为Java程序员带来了很多麻烦,比如最常见的空指 ...

  4. Oracle12c功能增强新特性之维护&amp;升级&amp;恢复&amp;数据泵等

    1.   内容提要 1)   表分区维护的增强. 2)   数据库升级改善. 3)   跨网络还原/恢复数据文件. 4)   数据泵的增强. 5)   实时ADDM. 6)   并发统计信息收集. 2 ...

  5. [USACO 04OPEN]MooFest

    Description 约翰的N 头奶牛每年都会参加“哞哞大会”.哞哞大会是奶牛界的盛事.集会上的活动很多,比如堆干草,跨栅栏,摸牛仔的屁股等等.它们参加活动时会聚在一起,第i 头奶牛的坐标为Xi,没 ...

  6. [HNOI 2014]米特运输

    Description 米特是D星球上一种非常神秘的物质,蕴含着巨大的能量.在以米特为主要能源的D星上,这种米特能源的运输和储 存一直是一个大问题.D星上有N个城市,我们将其顺序编号为1到N,1号城市 ...

  7. 【Bzoj 1835 基站选址】

    基站选址的区间里隐藏着DP优化的机密…… 分析:       不论是做过乘积最大还是石子合并,或者是其他的入门级别的区间DP题目的人呐,大米并认为读题后就能够轻松得出一个简洁明了的Dp转移方程.    ...

  8. 【LA 3027 Corporative Network】

    ·一些很可爱的询问和修改,放松地去用并查集解决. ·英文题,述大意: 输入n(5<=n<=20000)表示树有n个节点,并且会EOF结束地读入不超过 20000个操作,一共有两种:    ...

  9. poj 2774 最长公共子串 后缀数组

    Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 25752   Accepted: 10 ...

  10. 例10-10 uva10491(简单概率)

    题意: 在a+b扇门,a扇后面是牛,b扇后面是车.在你选择一扇门后,主持人为你打开另外c扇门,然后你再选一扇, 求是车的概率 ①先选牛:a/(a+b),然后还剩a+b-c-1扇门,其中b扇为车,所以a ...