HDOJ-1019 Least Common Multiple
http://acm.hdu.edu.cn/showproblem.php?pid=1019
题意:给出n个数,求它们的最小公倍数
对于n个数,它们的最小公倍数等于【前n-1个数的最小公倍数和第n个数】的最小公倍数
而前n-1个数的最小公倍数又等于【前n-2个数的最小公倍数和第n-1个数】的最小公倍数
以此类推..
所以,从第1和第2个数开始依次求出最小公倍数,然后迭代即可
# include <stdio.h> int a, n, Result; int Gcd(int x, int y)
{
if(y == 0)
return x;
return Gcd(y, x%y);
} int Lcm(int x, int y)
{
int t = Gcd(x, y);
return (x / t) * (y / t) * t;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
scanf("%d",&Result);
for(int i = 2; i <= n; i++)
{
scanf("%d",&a);
Result = Lcm(Result, a);
}
printf("%d\n",Result);
}
return 0;
}
HDOJ-1019 Least Common Multiple的更多相关文章
- HDOJ 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【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 ...
- 1019 Least Common Multiple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU - 1019 - Least Common Multiple - 质因数分解
http://acm.hdu.edu.cn/showproblem.php?pid=1019 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...
- 杭电1019 Least Common Multiple【求最小公倍数】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019 解题思路:lcm(a,b)=a*b/gcd(a,b) 反思:最开始提交的时候WA,以为是溢出了, ...
- HDU 1019 Least Common Multiple 数学题解
求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...
- HDU 1019 Least Common Multiple GCD
解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...
- HDU-1019 Least Common Multiple
http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
随机推荐
- eucMenu
- mysql 从data文件恢复数据库
安装在D:\mysql\mysql-5.6.24-winx64下的mysql 由于系统坏了,移到另外一台机器上启动 步骤如下 1.复制以前的mysql安装文件及data文件下:2.全新安装mysql3 ...
- Mongo服务器集群配置【转】
http://www.cnblogs.com/wly923/tag/MongoDB/ 当前标签: MongoDB Mongo服务器集群配置学习三——分片 风行影者 2013-04-14 22:35 ...
- SWTBOK測试实践系列(4) -- 软件測试技术的黑白之道
白盒測试和黑盒測试往往是项目中最受争议的两种測试类型,每一个人偏爱各不同.现实生活中行业人员大多喜欢白盒測试而忽视黑盒測试,那么项目中又应该怎样平衡这两类測试呢?我们先来看两个案例. 案例一: 某移动 ...
- GridControl 设置焦点单元格
gdvNew.Focus(); //GridControl 控件获取焦点 gdvNew.FocusedRowHandle = _smtReport.Count - 1; //设置焦点行 gdvNew. ...
- 自定义HttpHandler
1.创建自定义类型 2.继承IHttpHandler接口,并实现 3.配置Web.Config文件,注册类型 4.访问 public class QuickMsgSatisticsHandler : ...
- EF中的连接字符串
映射视图是每个实体集和关联的映射中指定的可转换的可执行表示. 包括两部分: 查询视图 表示从数据库架构转到概念架构所需的规范装换 更新视图 表示从概念模型转到数据库架构所需的规范转换 如果应用程序仅用 ...
- oracle 11g 64位安装32位客户端和PL/SQL
转自:http://www.360doc.com/content/14/0602/10/4903283_382949382.shtml 这个你需要安装一个32位的oracle客户端才能使用plsq ...
- linux环境下jdk 安装以及maven私服搭建
1:准备资源 linux服务器,jdk和nexus 安装包 2:网络通畅,保持windows端和linux服务器端网络通畅. 3: 安装jdk和配置环境变量 进入到 ...
- Private Members in JavaScript
Private Members in JavaScript Douglas Crockford www.crockford.com JavaScript is the world's most mis ...