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 ...
随机推荐
- windows puppet manifests 文件维护
初级 puppet windows agent实现简单的msi格式安装包安装及bat文件创建;
- c语言指向结构体数组的指针
#include <stdio.h> #include <stdlib.h> struct dangdang { ]; ]; ]; int num; int bugnum; ] ...
- Quartz集成springMVC 的方案一
Quartz是一个开放源码项目,专注于任务调度器. springMVC 具体的搭建框架就不具体说明,接下来直接描述把Quartz集成到springMVC 框架中. 步骤: 1.引入所需要的jar包 2 ...
- Java中日期时间API小结
Java中为处理日期和时间提供了大量的API,确实有把一件简单的事情搞复杂的嫌疑,各种类:Date Time Timestamp Calendar...,但是如果能够看到时间处理的本质就可以轻松hol ...
- (转)[老老实实学WCF] 第二篇 配置WCF
在上一篇中,我们在一个控制台应用程序中编写了一个简单的WCF服务并承载了它.先回顾一下服务端的代码: using System; using System.Collections.Generic; u ...
- 《第一行代码》学习笔记5-活动Activity(3)
1.Menu:让菜单得到展示的同时,不占用任何屏幕的空间. public boolean onCreateOptionsMenu(Menu menu){ getMenuInflater().infla ...
- 全世界最详细的图形化VMware中linux环境下oracle安装(三)【weber出品必属精品】
数据库软件和数据库都建好了,基本上可以说完成90%的工作,但是美中不足的就是企业管理器还没有安装好,现在我们就开始安装企业管理器吧. 安装之前我们先将补丁给补上.补丁我们也是采用禁默安装.补丁:p83 ...
- iOS_SN_BlueTooth( 一)蓝牙相关基础知识
原文 http://www.cocoachina.com/ios/20150915/13454.html 作者:刘彦玮 蓝牙常见名称和缩写 MFI ======= make for ipad ,ip ...
- winform textbox 的自动实现功能
好久没写博客了,主要是太懒了,之前因为做bs的比较多现在想转cs端了,虽然现在做cs也一年了,可接触的东西太过零碎了,以至于感觉这一年好像什么都没有学到.估计是因为学了之后没有记录,不扎实,然后又忘记 ...
- meta便签的用法
1.定义编码规则,<meta http-equiv="Content-Type" content="text/html; charset=utf-8" / ...