Least Common Multiple

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 45020    Accepted Submission(s): 16916

Problem 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

Source

East Central North America 2003, Practice

Recommend

JGShining   |   We have carefully selected several similar problems for you:  1005 1021 1061 1049 1108

题意:
水题。求几个数的最小公倍数。

思路:辗转相除法,输入一个数算一次。
AC代码:
#include<iostream>
using namespace std;
int main()
{
int t,n;
long long a;
cin>>t;
while(t--)
{
cin>>n;
long long m=1;
for(int i=1;i<=n;++i)
{
cin>>a;
long long b=m,c=a;
if(c>b)
{
long long tmp=b;
b=c;
c=tmp;
}
while(b%c!=0)
{
long long d=b%c;
if(d>c)
{
b=d;
}
else 
{
b=c;
c=d;;
}
}
m=m*a/c;
}
cout<<m<<endl;
}
return 0;
}

HDU1019的更多相关文章

  1. hdu1019 Least Common Multiple

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

  2. HDU-1019 Least Common Multiple

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

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

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

  4. HDU1019 Least Common Multiple(多个数的最小公倍数)

    The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...

  5. [暑假集训--数论]hdu1019 Least Common Multiple

    The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...

  6. OJ题目分类

    POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...

随机推荐

  1. LaTex学习笔记(一)

    1. 语法 命令 普通命令 环境 数据 注释 2. 物理结构 导言 指定文档类型,引入宏包,定义命令,环境等 \documentclass[options]{class} \usepackage[op ...

  2. LoadRunner编程之跳出迭代

    LoadRunner编程之跳出迭代 51Testing软件测试网3p6pK.Yo LoadRunner中 提供了函数exit(-1)来结束迭代. 使用return 0 来结束本次迭代,进入下一次迭代. ...

  3. 利用K-means聚类分类,进行特征学习

    这只是老师安排的一个实验,准备过程中遇到各种问题,现在贴出来供大家参考,是Andrew Ng参与的研究, 论文依据如下,第二篇是一篇相关的论文, Learning Feature Representa ...

  4. 【转载】Android内存泄露

    相信一步步走过来的Android从业者,每个人都会遇到OOM的情况.如何避免和防范OOM的出现,对于每一个程序员来说确实是一门必不可少的能力.今天我们就谈谈在Android平台下内存的管理之道,开始今 ...

  5. Android自动化测试 - MonkeyRunner(一)介绍

    MonkeyRunner介绍: MonkeyRunner是Google提供的一个基于坐标点的Android黑盒自动化测试工具. Monkeyrunner工具提供了一套API让用户/测试人员来调用,调用 ...

  6. 种树 & 乱搞

    题意: 在一个(n+1)*(m+1)的网格点上种k棵树,树必须成一条直线,相邻两棵树距离不少于D,求方案数. SOL: 这题吧...巨坑无比,本来我的思路是枚举每一个从(0,0)到(i,j)的矩形,然 ...

  7. 20145308刘昊阳 《Java程序设计》第6周学习总结

    20145308刘昊阳 <Java程序设计>第6周学习总结 教材学习内容总结 第10章 输入/输出 10.1 InputStream与OutputStream 10.1.1 串流设计概念 ...

  8. Android 模糊效果

    (1)FastBlur http://www.cnblogs.com/CharlesGrant/p/4813735.html (2)StackBlur 基于RenderScript,StackBlur ...

  9. 关于vim插件

    本人比较喜欢amix它集成了很多插件. 1.mru.vim:用于打开最近使用过的文件 使用命令: :MRU     打开最近的文件列表 上下箭头可以移动关标 :o 在新窗口中打开文件 2.NERD T ...

  10. CODEVS 1817 灾后重建 Label:Floyd || 最短瓶颈路

    描述 灾后重建(rebuild)  B地区在地震过后,所有村庄都造成了一定的损毁,而这场地震却没对公路造成什么影响.但是在村庄重建好之前,所有与未重建完成的村庄的公路均无法通车.换句话说,只有连接着两 ...