HDU-1019 Least Common Multiple
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
#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的更多相关文章
- 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 ...
- ACM hdu 1019 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 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...
- HDU 1019 Least Common Multiple 数学题解
求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...
- HDU 1019 Least Common Multiple GCD
解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...
- 背包系列练习及总结(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 ...
- HDU 4913 Least common multiple
题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...
- HDU 3092 Least common multiple 01背包
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
随机推荐
- CDT 错误 Cannot run program "gcc"
Eclipse+CDT 编辑C/C++程序出错误: 出现编译错误: **** Rebuild of configuration Debug for project example **** **** ...
- ERROR 1045 (28000): Access denied for user 'root'@'localhost'
# /etc/init.d/mysql stop# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &# mysq ...
- Linux的前世今生
Linux的起源 说到Linux[/ˈlɪnəks/],想必大家也会自然而然地想到他的创始人——被称为“Linux之父”的林纳斯·托瓦兹(Linus Torvalds).其实,在Linux出现之前,还 ...
- leetcode345——Reverse Vowels of a String(C++)
Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...
- SGU 218.Unstable Systems
题意: 有n(n<500)台机器,和500个程序.不同的程序在不同的机器上运行有着不同的不稳定度s[i][j].求最小的最大稳定度及其方案. Solution: 比较经典的二分图模型. 建图很简 ...
- 《C语言学习笔记》指针数组及其应用
C语言中,最灵活但又容易出错的莫过于指针了.而指针数组,是在C中很常见的一个应用.指针数组的意思是说,这个数组存储的所有对象都为指针.除了存储对象为指针,即一个地址外,其它操作和普通数组完全一样. # ...
- jsp查询页面和结果页面在同一页面显示和交互
用frameset实现查询页面和结果页面在同一页面 用target实现交互显示在同一页面上 请参照以下方法解决: main.jsp: <html> <head> <met ...
- 2014年度辛星html教程夏季版第二节
上面一节中我们介绍了HTML文件的书写和几个标签,接下来我们来认识几个其他的标签,这里我们主要介绍一下head标签和文本标签. ***************head标签*************** ...
- asp.net管道模型
查了很多资料,终于大概弄懂管道模型(注意并非指定是asp.net范畴)是个什么概念了,其实就是从Unix移植过来的一种概念,也可以说是一种模式吧(只允许一头读,一头写,并且读完了就会自动消失). as ...
- bzoj 3165: [Heoi2013]Segment 动态凸壳
3165: [Heoi2013]Segment Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 202 Solved: 89[Submit][Stat ...