K - Least Common Multiple
Description
Input
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
corresponding LCM. All results will lie in the range of a 32-bit
integer.
Sample Input
3 5 7 15
6 4 10296 936 1287 792 1
Sample Output
#include<stdio.h>
int gcd(int a,int b)
{
if(b==) return a;
return gcd(b,a%b);
}
int main()
{
int t;
int n,a,b,i;
int cnt;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
cnt=a=;
for(i=;i<=n;i++)
{
scanf("%d",&b);
cnt=a/gcd(a,b)*b;
a=cnt;
}
printf("%d\n",cnt);
}
return ;
}
K - Least Common Multiple的更多相关文章
- HDOJ2028Lowest Common Multiple Plus
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU-1019 Least Common Multiple
http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- Lowest Common Multiple Plus
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- ACM-简单题之Least Common Multiple——hdu1019
***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...
- 1019 Least Common Multiple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 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> ...
随机推荐
- php开发必备小工具
/*递归删除目录及目录下的文件*/ function del_dir($dir){ $files = new DirectoryIterator($dir); foreach ($files as $ ...
- 从客户端(txtContent="<p>1</p>")中检测到有潜在危险的 Request.Form 值
输入1也报这个错误, <pages validateRequest="false" 改了也不行,在页头改也不行.到底什么情况呢? 从这个地方找到了答案:http://nt.d ...
- MySQL数据库的一些基本操作及注释
--Created by mac on 2017/1/4. -- MySQL数据库 -- ****************** 一. 连接数据库服务器的基础命令 ******************* ...
- JAVA基础----java中E,T,?的区别?
http://825635381.iteye.com/blog/2017650 遇到<A>,<B>,<K,V>等,是用到了java中的泛型. 一般使用<T&g ...
- Android中View的基础知识
View的界限 View就是我们看到的界面,有四个界限范围分别是, Top/Left, Bottom/Right,坐标系从左上到右下.这四个值可以通过任何View的子类调用getTop()/get.. ...
- Spark高级数据分析中文版-读者交流
第二章: 备注:1.本书第二章样例数据由于才有的是短链接,国内的用户可能无法下载.我把数据集拷贝到百度网盘上.大家可以从这个地方下载:http://pan.baidu.com/s/1pJvjHA7 谢 ...
- Tomcat Shell脚本(启动|关闭|重启|状态)
#!/bin/bash # # chkconfig: - # description: Tomcat start/stop/status script #Location of JAVA_HOME ( ...
- php __invoke 和 __autoload
当在对象后面添加()时候调用 __invoke <?php class Person { private $name; private $age; public function __const ...
- SQL简单语法
(1)select SELECT 列名称 FROM 表名称 (2)distinct SELECT DISTINCT 列名称 FROM 表名称 SELECT * FROM 表名称 (3)where SE ...
- android之fragment
觉得写得好:http://blog.csdn.net/shulianghan/article/details/38064191