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. uri,url.urn

    uri:Web上可用的每种资源 - HTML文档.图像.视频片段.程序等 - 由一个通过通用资源标志符(Universal Resource Identifier, 简称"URI" ...

  2. (转载)如何借助KeePassX在Linux上管理多个密码

    转自:http://netsecurity.51cto.com/art/201311/417764.htm 如今,基于密码的身份验证在网上非常普遍,结果你恐怕数不清自己到底在使用多少个密码.实际上,据 ...

  3. 将一个正整数分解为m个2的n次方的和

    -- ============================================= -- Author:      <maco_wang> -- Create date: & ...

  4. Windows下MySQL zip版的简单安装

    1.下载MySQL-5.5.10-win32.zip的版本.2.解压到任意路径,比如"D:\Programm Files\".3.进入MySQL路径,复制my-small.ini为 ...

  5. u盘中放入大于4g单独文件失败解决

    u盘中文件格式通常为FAT32,需要转换为NTFS格式 在win7中cmd调出命令行,输入: convert H: /fs:ntfs (H为u盘位置)

  6. 对NLP的一些新认识

    其实这是老板让上交的一份总结,贴出来,欢迎朋友们批评指正. 最近看了一部分关于NLP的几篇论文,其中大部分为神经网络实现, 从基本的HMM算法实现,到LSTM实现,有很多方法可以用来处理NLP任务中的 ...

  7. 20145223《Java程序程序设计》实验报告5

    20145223杨梦云<Java网络编程> 一.实验内容 ·1.运行下载的TCP代码,结对进行,一人服务器,一人客户端: ·2.利用加解密代码包,编译运行代码,一人加密,一人解密: ·3. ...

  8. js从字符串中提取身份证号,连续18位数字

    <!DOCTYPE html> <html> <head> <title>提取身份证号</title> <meta charset=& ...

  9. HDU5727 Necklace(枚举 + 二分图最大匹配)

    题目大概说有n个yang珠子n个yin珠子,要交替串成一个环形项链,有些yang珠子和某个yin珠子相邻这个yang珠子会不高兴,问最少有几个yang珠子不高兴. 自然会想到直接用状压DP去解,转移很 ...

  10. Codeforces 552C Vanya and Scales(思路)

    题目大概说有101个质量w0.w1.w2.....w100的砝码,和一个质量m的物品,问能否在天平两边放物品和砝码使其平衡. 哎,怎么没想到..注意到w0.w1.w2.....w100—— 把m转化成 ...