Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

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.

 

Input

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

Output

For 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<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的更多相关文章

  1. HDOJ2028Lowest Common Multiple Plus

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. HDU-1019 Least Common Multiple

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

  4. HDOJ 1019 Least Common Multiple(最小公倍数问题)

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

  5. Lowest Common Multiple Plus

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...

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

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

  7. 1019 Least Common Multiple

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

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

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

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

随机推荐

  1. php开发必备小工具

    /*递归删除目录及目录下的文件*/ function del_dir($dir){ $files = new DirectoryIterator($dir); foreach ($files as $ ...

  2. 从客户端(txtContent="<p>1</p>")中检测到有潜在危险的 Request.Form 值

    输入1也报这个错误, <pages validateRequest="false" 改了也不行,在页头改也不行.到底什么情况呢? 从这个地方找到了答案:http://nt.d ...

  3. MySQL数据库的一些基本操作及注释

    --Created by mac on 2017/1/4. -- MySQL数据库 -- ****************** 一. 连接数据库服务器的基础命令 ******************* ...

  4. JAVA基础----java中E,T,?的区别?

    http://825635381.iteye.com/blog/2017650 遇到<A>,<B>,<K,V>等,是用到了java中的泛型. 一般使用<T&g ...

  5. Android中View的基础知识

    View的界限 View就是我们看到的界面,有四个界限范围分别是, Top/Left, Bottom/Right,坐标系从左上到右下.这四个值可以通过任何View的子类调用getTop()/get.. ...

  6. Spark高级数据分析中文版-读者交流

    第二章: 备注:1.本书第二章样例数据由于才有的是短链接,国内的用户可能无法下载.我把数据集拷贝到百度网盘上.大家可以从这个地方下载:http://pan.baidu.com/s/1pJvjHA7 谢 ...

  7. Tomcat Shell脚本(启动|关闭|重启|状态)

    #!/bin/bash # # chkconfig: - # description: Tomcat start/stop/status script #Location of JAVA_HOME ( ...

  8. php __invoke 和 __autoload

    当在对象后面添加()时候调用 __invoke <?php class Person { private $name; private $age; public function __const ...

  9. SQL简单语法

    (1)select SELECT 列名称 FROM 表名称 (2)distinct SELECT DISTINCT 列名称 FROM 表名称 SELECT * FROM 表名称 (3)where SE ...

  10. android之fragment

    觉得写得好:http://blog.csdn.net/shulianghan/article/details/38064191