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. opengl常用函数

    glAccum 操作累加缓冲区   glAddSwapHintRectWIN 定义一组被 SwapBuffers拷贝的三角形   glAlphaFunc允许设置alpha检测功能   glAreTex ...

  2. Android 通过Java代码生成创建界面。动态生成View,动态设置View属性。addRules详解

    废话不多说,本文将会层层深入给大家讲解如何动态的生成一个完整的界面. 本文内容: Java代码中动态生成View Java代码中动态设置View的位置,以及其他的属性 LayoutParams详解 一 ...

  3. ASP.Net MVC开发基础学习笔记(4):校验、AJAX与过滤器

    一.校验 — 表单不是你想提想提就能提 1.1 DataAnnotations(数据注解) 位于 System.ComponentModel.DataAnnotations 命名空间中的特性指定对数据 ...

  4. C# 枚举(enum)

    public enum EnumStatus { On=0, Off=1 } //获取值:0 Convert.ToInt32(EnumStatus.On); //获取On EnumStatus.On; ...

  5. redis 存储session实现session共享

    nginx 作为代理 tomcat集群 redis存储共享session nginx采用轮询方式将动态请求反向代理给tomcat,tomcat通过加载相应jar包方式实现获得redis中共享的sess ...

  6. fzu月赛 2203 单纵大法好 二分

    Accept: 8    Submit: 18Time Limit: 5000 mSec    Memory Limit : 65536 KB  Problem Description 人在做,天在看 ...

  7. spring MVC 的MultipartFile转File??

    MultipartFile file = xxx;         CommonsMultipartFile cf= (CommonsMultipartFile)file;         DiskF ...

  8. UITextField最大字符数和最大字节数的限制

    UITextView,UITextfield中有很多坑,网上的方法也很多,但是用过之后暂时没有发现一个好用.这里我给大家几组测试用例可以一试,为啥不好用. 限制10个字节,输入2个Emoj之后是8个字 ...

  9. Python学习笔记04

    语句之后有冒号,表示有一个语句块,且以四个空格的缩进来表示隶属关系. 与C# 相比,没有了{},没有了(),被冒号和缩进取代了 if,while,for,range,continue,break if ...

  10. HDU4807 Lunch Time(费用流变种)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4807 Description The campus of Nanjing Universit ...