http://acm.hdu.edu.cn/showproblem.php?pid=1019

Least Common Multiple

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

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

#include "stdio.h"
long int gb(long m,long n)
{
if(m>&&n>)
{
long a,b,r;
if(n>m)
{
r=m;
m=n;
n=r;
}
a=m;
b=n;
while(r!=)
{
r=a%b;
a=b;
b=r;
}
return m/a*n;
}
else
return ;
}
int main()
{
int i,n,a,b,t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf("%d",&a);
for(i=;i<n;i++)
{
scanf("%d",&b);
a=gb(a,b);
}
printf("%d\n",a);
}
}
#include"stdio.h"
int mcm( long x, long y)
{
long t;
while(y)
{
t=x%y;
x=y;
y=t;
}
return x;
}
int main()
{
long n,m;
long x,y,t1;
while(scanf("%lld",&n)!=EOF)
{
while(n--)
{
scanf("%ld",&m);
scanf("%ld",&x); while(--m)
{
scanf("%ld",&y);
t1=mcm(x,y);
x=x*y/t1;
}
printf("%ld\n",x);
}
}
return ;
}

HDU-1019 Least Common Multiple的更多相关文章

  1. HDU 1019 Least Common Multiple【gcd+lcm+水+多个数的lcm】

    Least Common Multiple Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  2. ACM hdu 1019 Least Common Multiple

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

  3. HDU - 1019 - Least Common Multiple - 质因数分解

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...

  4. HDU 1019 Least Common Multiple 数学题解

    求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...

  5. HDU 1019 Least Common Multiple GCD

    解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...

  6. 背包系列练习及总结(hud 2602 && hdu 2844 Coins && hdu 2159 && poj 1170 Shopping Offers && hdu 3092 Least common multiple && poj 1015 Jury Compromise)

    作为一个oier,以及大学acm党背包是必不可少的一部分.好久没做背包类动规了.久违地练习下-.- dd__engi的背包九讲:http://love-oriented.com/pack/ 鸣谢htt ...

  7. HDU 4913 Least common multiple

    题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...

  8. HDU 3092 Least common multiple 01背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...

  9. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  10. HDOJ 1019 Least Common Multiple(最小公倍数问题)

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

随机推荐

  1. http 请求头

    HTTP Request的Header信息 1.HTTP请求方式 如下表: GET 向Web服务器请求一个文件 POST 向Web服务器发送数据让Web服务器进行处理 PUT 向Web服务器发送数据并 ...

  2. 九度OJ 1516 调整数组顺序使奇数位于偶数前面 -- 归并排序

    题目地址:http://ac.jobdu.com/problem.php?pid=1516 题目描述: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的 ...

  3. 九度OJ 1452 搬寝室 -- 动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1452 题目描述: 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3 ...

  4. Linux错误码的含义

    C Name Value Description EPERM 1 Operation not permitted ENOENT 2 No such file or directory ESRCH 3 ...

  5. js点击 密码输入框密码显示隐藏

    很多密码框都有个眼睛标记,点击能显示密码.原理就是点击切换password为text等显示 下面上代码 <!DOCTYPE html> <html> <head> ...

  6. linux JAVA JDK环境配置

    export JAVA_HOME=/usr/local/jdk1.7.0_45export JRE_HOME=/usr/local/jdk1.7.0_45/jreexport CLASSPATH=.: ...

  7. Hibernate一对一双向关联(外键)

    网站上各种搜索,都是一些清晰或者不清晰的例子,但是用下来一是确实不给力,二是完全不知道所以然. 后来终于在书中查到了就在这里记一下. 首先要说明,这里只解释双向一对一只有一个表里面有外键的情况. 就以 ...

  8. Java多线程初学者指南(11):使用Synchronized块同步方法

    synchronized关键字有两种用法.第一种就是在<使用Synchronized关键字同步类方法>一文中所介绍的直接用在方法的定义中.另外一种就是synchronized块.我们不仅可 ...

  9. CTSC && APIO 总结

    先说CTSC吧,第一试其实不难但是下意识觉得CTSC不就只能骗分吗,然后就全上暴力了.然而第二题再一次看漏了条件,即答案总和小于等于1e6.第三题现在回想起来要不然就是没有思考,要不然就是没学过数学, ...

  10. hdu 4435

    一道枚举+搜索题: 很容易看出这道题目要求尽量不在大的城市里面建加油站: 所以从最大的城市开始枚举! 代码: #include<cstdio> #include<cmath> ...