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 ...
随机推荐
- 合天网安实验室学习笔记----Linux基础
一.Linux的发展 linux kernel的版本是:2.6.32-279.el6.x86_64,此格式为:主版本.次版本.释出版本-修改版本 次版本为奇数:测试版: 次版本为偶数:稳定版: Lin ...
- LeetCode 191. Number of 1 Bits Question
题意:给你一个整数,计算该整数的二进制形式里有多少个“1”.比如6(110),就有2个“1”. 一开始我就把数字n不断右移,然后判定最右位是否为1,是就cnt++,否则就继续右移直到n为0. 可是题目 ...
- pyqt例子搜索文本
#!/usr/bin/env python #-*- coding:utf-8 -*- import sip sip.setapi('QString', 2) sip.setapi('QVariant ...
- HDOJ 1316 How Many Fibs?
JAVA大数.... How Many Fibs? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- IT痴汉的工作现状25-技术之养成
要想成为技术大牛,除了天赋以外,更与后天的刻苦努力分不开.伟仔我天生愚顿.工作多年后仍与大牛相差甚远,更加觉得技术的养成是一个异常困难的过程. 是我不用功吗?我不这样觉得.伟仔尽管是个懒人,但对于技术 ...
- FileZilla 安装配置参考
http://www.admin10000.com/document/72.html 解决 NAT issue https://wiki.filezilla-project.org/Network_C ...
- (转) 值不能为空。参数名viewinfo(microsoft.sqlserver.management.sqlstudio.explorer)
打开MSSQL 2008 R2的时候,展开数据库都显示以下的错误提示: 值不能为空.参数名viewinfo(microsoft.sqlserver.management.sqlstudio.explo ...
- poj3090欧拉函数求和
E - (例题)欧拉函数求和 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB ...
- CString 字符串转化和分割
1.格式化字符串 CString s;s.Format(_T("The num is %d."), i);相当于sprintf() 2.转为 int 转10进制最好用_ttoi() ...
- 【android】android中activity的生命周期
activity生命周期: 实例代码: public class DemoActivity extends Activity { //1.activity第一次被创建的时候,执行 @Override ...