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. 关于AVAudioPlayer

    IOS中有三种播放音频的方式:AVAudioPlayer.音频服务.音频队列. 此文主要讲AVAudioPlayer,其他两个请见相关文章. AVAudioPlayer在AVFoundation框架下 ...

  2. redis研究之watch

    具体的看注释,代码如下: public static void TransTest() { RedisClient client1 = new RedisClient(host, port); Red ...

  3. 关于C++对汉字拼音的处理——终结篇

    以前写过了3个博文,都是关于汉字转拼音的,后来发现都不是很“完美”的解决方案,第一个和第二个利用的unicode编码的范围进行确定汉字的拼音,但是难免有遗漏,这个在后面的实践中发现的,后来第三个方法是 ...

  4. 使用link在两个容器之间建立连接(mysql)

    在使用Docker的时候我们会常常碰到这么一种应用,就是我需要两个或多个容器,其中某些容器需要使用另外一些容器提供的服务.比如这么一种情况:我们需要一个容器来提供mysql的数据库服务,而另外两个容器 ...

  5. JavaScript入门介绍(二)

    JavaScript入门介绍 [函数] 函数function 是Javascript的基础模块单元,用于代码的复用.信息影藏和组合调用. function a(){} 函数对象Function Lit ...

  6. CentOS 6.4 播放avi格式的视频文件

    1. 需要先进行相关的yum源的导入: rpm -Uhv http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0. ...

  7. C语言和C++中动态申请内存

      在C语言和C++的动态内存的使用方法是不同的,在C语言中要使用动态内存要包含一个头文件即 #include<malloc.h> 或者是#include<stdlib.h>  ...

  8. ul动态增加li

    --> aaa bbb <%@ page language="java" import="java.util.*" pageEncoding=&qu ...

  9. CSS3 学习

    border-radius: 半径,不用学了,用得很熟了,但要记得它的某一个角的写法是border-top/bottom-left/right-radius: ,参数中的两个值为先左右后上下,支持百分 ...

  10. asp.net core 认证及简单集群

    众所周知,在Asp.net WebAPI中,认证是通过AuthenticationFilter过滤器实现的,我们通常的做法是自定义AuthenticationFilter,实现认证逻辑,认证通过,继续 ...