ACM Least Common Multiple
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的更多相关文章
- 2028 ACM Lowest Common Multiple Plus
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2028 思路:最一想到的就是暴力求解,从1开始一直到最后的答案,一直来除以给出的数列的数,直到余数为0:当然 ...
- ACM hdu 1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)
Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...
- HDU-1019 Least Common Multiple
http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...
- ACM-简单题之Least Common Multiple——hdu1019
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- 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 ...
- hdu_1019Least Common Multiple(最小公倍数)
太简单了...题目都不想贴了 //算n个数的最小公倍数 #include<cstdio> #include<cstring> #include<algorithm> ...
- HDU 4913 Least common multiple
题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...
- HDU 3092 Least common multiple 01背包
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...
随机推荐
- vue中的vue-cli
在前面的学习过程中我相信你们已经对vue有了一定的了解,现在我们来看一下vue中的vue-cli. 学习这个我们首先需要的是node环境的,如果你的网络环境慢的话建议安装淘宝镜像,在cmd中输入 np ...
- Android学习——NDK交叉编译
原创作品,转载请注明出处,严禁非法转载.如有错误,请留言! email:40879506@qq.com 一. 环境1.GNU/Linux Ubuntu12.04操作系统(x86) 二. 下载NDK安装 ...
- POJ-3641 Pseudoprime numbers---快速幂
题目链接: https://vjudge.net/problem/POJ-3641 题目大意: 问p是不是伪素数.伪素数条件:①p不是素数.② ap = a (mod p). 思路: 直接快速幂模板+ ...
- __dict__
类有一个__dict__字典属性,保存了当前类的每一个成员,举例如下: >>> class A: def __init__(self,value): self.value=value ...
- 数据库性能优化(database tuning)性能优化绝不仅仅只是索引
一毕业就接触优化方面的问题,专业做优化也有至少5年之多的时间了,可现在还是经常听到很多人认为优化很简单,就是建索引的问题,这确实不能怪大家,做这行20多年的时间里,在职业生涯的每个阶段,几乎都能听到这 ...
- Spring(5)——Spring 和数据库编程
传统 JDBC 回顾 JDBC 我们一定不陌生,刚开始学习的时候,我们写过很多很多重复的模板代码: public Student getOne(int id) { String sql = " ...
- win7安装JDK6
注:虽然9已经出来了,但是今天刚好业务需要要装JDK6,所以以JDK 6作为演示,同样适用于JDK 7.8的安装. 安装 基本上一直点下一步就可以. 此处可修改安装路径. 我将JDK的安装路径设置成了 ...
- ls-dyna基础教程
刚刚开始使用ls-dyna,几天前还只知道点开dyna界面,然后就没有然后了,没人带,资料也没多少,但是科研还得继续往下做呀(手动滑稽),通过在仿真论坛上搜索相关的资料,并通过自己的一步步操作,做了大 ...
- C# 关键字替换
/// <summary> /// 关键字替换 /// </summary> /// <param name="body"></param ...
- 浅谈linux静态库、动态库。
动态库又叫动态共享文件(.so,Dynamic Shared Objects)和静态库(.a)都是将一些待重用的公共代码打包成一种特殊的重定位目标文件. 在使用时,连接器会将静态库中所有的代码,编译到 ...