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. socket编程学习

    socket: 也称作套接字,应用程序通常通过套接字向网络发出请求或者应答网络请求. 常用的套接字API函数: 1.socket(): 函数原型为:int socket(int domain, int ...

  2. ios内购

    1.添加框架,storeKit.framework 需要真机调试 /* 内购五步: 1.请求可销售商品的列表 2.展示课销售的商品 3.点击购买 4.开具小票 5.创建交易对象并添加到交易队列 6.创 ...

  3. FreeMarker学习(宏<#macro>的使用)

    原文链接:https://my.oschina.net/weiweiblog/blog/506301?p=1 用户定义指令-使用@符合来调用  有两种不同的类型:Macro(宏)和transform( ...

  4. 【hibernate 执行方法未插入数据库】hibernate的save方法成功执行,但是未插入到数据库

    今天做项目,碰上这个问题: hibernate的save方法成功执行,但是未插入到数据库. Dao层代码: @Override public void save(T t) { this.getSess ...

  5. ThinkPHP去重 distinct和group by

    转自:http://blog.csdn.net/helencoder/article/details/50328629 近期项目中,遇到数据表去重要求,对于ThinkPHP的去重有了更加准确的认识和体 ...

  6. nginx日志中文变成类型\xE9\xA6\x96\xE9\xA1\xB5-\xE6\x8E\xA8\xE8\x8D\x90的东西

    感谢 http://my.oschina.net/leejun2005/blog/106791 代码如下: public class App { public static String str2He ...

  7. eclipse->project->clean…作用

    其实主要作用就是把编译好的class等文件删除,激活eclipse的自动编译.解决的问题就是,有时候你把代码改了,但因为一些未知的原因,eclipse的自动编译没有成功,导致运行结果不正常.当你的工程 ...

  8. XSS 跨站脚本攻击之构造剖析(二)

    1.利用字符编码 (1)字符编码在跨站脚本中经常运用到,透过这种技巧,不仅能让XSS代码绕过服务端的过滤,还能更好的隐藏ShellCode (2)使用一个XSS编码工具,以便对字符串进行十进制和十六进 ...

  9. [工作中的设计模式]原型模式prototype

    一.模式解析 提起prototype,最近看多了js相关的内容,第一印象首先是js的原型 var Person=function(name){ this.name=name; } Person.pro ...

  10. 20145223《Java程序程序设计》第3周学习总结

    20145223 <Java程序设计>第3周学习总结 教材学习内容总结 第四章内容 1.类与对象 如何定义一个包含有几个值域(Field成员)就是需要我们定义一个类(Class),书上给的 ...