HDU1019
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的更多相关文章
- hdu1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- 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************************** ...
- HDU1019 Least Common Multiple(多个数的最小公倍数)
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- [暑假集训--数论]hdu1019 Least Common Multiple
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- OJ题目分类
POJ题目分类 | POJ题目分类 | HDU题目分类 | ZOJ题目分类 | SOJ题目分类 | HOJ题目分类 | FOJ题目分类 | 模拟题: POJ1006 POJ1008 POJ1013 P ...
随机推荐
- 第一个java程序hello world
首先需要配置环境,没配置的请参考:详细配置教程:http://www.cnblogs.com/qq1871707128/p/6047232.html 切入主题: java基础首先得了解基本的dos命令 ...
- ado.net增删改查操作
ado.net是数据库访问技术将数据库中的数据,提取到内存中,展示给用户看还可以将内存中的数据写入数据库中去 并不是唯一的数据库访问技术,但是它是最底层最基础的数据库访问技术 使用ado.net对数据 ...
- LoadRunner 常用C语言函数使用
strlen:获取字符串的长度 char str[20]="容我想想"; int len; len = strlen(str); lr_output_message("s ...
- 记一次小团队Git实践(下)
在上篇中,我们已经能基本使用git了,接下来继续更深入的挖掘一下git. 更多的配置自定义信息 除了前面讲的用户名和邮箱的配置,还可以自定义其他配置: # 自定义你喜欢的编辑器,可选 git conf ...
- 用val()获取与设置input的值
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- js-面向对象的程序设计,函数表达式
面向对象的程序设计: 1.属性类型:数据属性.访问器属性 数据属性:wirtable:false –只读:如果尝试为它赋值,会忽略 Configurable:false—不能从对象中删除属性 在调用O ...
- 短信猫 TIdTCPServer TIdTCPClient
短信猫 服务端: IdTCPServer1: TIdTCPServer; IdAntiFreeze1: TIdAntiFreeze; unit UnitSever; interface uses Wi ...
- 比较全的JS checkbox全选、取消全选、删除功能代码
看下面两种实现方法: JS checkbox 方法一: 复制代码 代码如下: function checkAll() { var code_Values = document.all['code_Va ...
- unity update 和fixedudpate
但是Update会在每次渲 染新的一帧时被调用. 而FixedUpdate会在每个固定的时间间隔被调用,
- 微软曝光眼球追踪新专利,未来或将可以使用眼球控制HoloLens
想要在增强现实(AR)和虚拟现实(VR)中获得感官能力,计算机的配合非常重要.如何能够更好的追踪我们所感知的,计算机判断用户目光所向的能力就必须进一步提高.根据微软新曝光的专利,可能已经有一个解决方案 ...