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的更多相关文章

  1. HDOJ 1019 Least Common Multiple(最小公倍数问题)

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

  2. 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 ...

  3. ACM hdu 1019 Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

  4. 1019 Least Common Multiple

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  5. HDU - 1019 - Least Common Multiple - 质因数分解

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...

  6. 杭电1019 Least Common Multiple【求最小公倍数】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1019 解题思路:lcm(a,b)=a*b/gcd(a,b) 反思:最开始提交的时候WA,以为是溢出了, ...

  7. HDU 1019 Least Common Multiple 数学题解

    求一组数据的最小公倍数. 先求公约数在求公倍数.利用公倍数,连续求全部数的公倍数就能够了. #include <stdio.h> int GCD(int a, int b) { retur ...

  8. HDU 1019 Least Common Multiple GCD

    解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...

  9. HDU-1019 Least Common Multiple

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...

  10. Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】

    Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...

随机推荐

  1. win7系统如何恢复administrator用户

    默认情况下,administrator用户是禁用的. 要恢复的话,右键单击我的电脑 管理-->本地用户和组-->用户-->右键属性 把"账户已禁用"前的选择符号去 ...

  2. Exchange Server 2010/2013架构改变

    Exchange Server 2010架构 Exchange Server 2013架构

  3. JAVA日期处理(Timestamp)

    要写一些与数据库连接时的日期处理,pstmt.setDate()的类型是java.sql.Date类型,这种符合规范的类型其实并没有把时分秒存进数据库,所以存取时就应该用setTimestamp()或 ...

  4. JDBC中Statement接口提供的execute、executeQuery和executeUpdate之间的区别

    Statement 接口提供了三种执行 SQL 语句的方法:executeQuery.executeUpdate 和 execute.使用哪一个方法由 SQL 语句所产生的内容决定. 方法execut ...

  5. autoitv3点击windows界面

    在自动化测试过程中会遇到如下windows安全认证,需要输入账号和密码,这个认证对话框不属于element元素.无法用selenium操作,需要用autoitv3操作,输入账号密码后,再进行web元素 ...

  6. Direct3D 11的流水线

    流水线 流水线(Pipeline)是理解D3D必须要掌握的概念. 整个流水线有很多步骤,有的步骤是固定功能,不用怎么配置,有的步骤是要写代码的,也就是所谓的着色器程序(Shader). 一般来说,将流 ...

  7. Android开发学习之Intent具体解释

    Intent简单介绍和具体解释:           Intent:协助应用间的交互与通信,Intent负责相应用中一次操作的动作.动作涉及的数据.附加数据进行描写叙述.               ...

  8. UltraEdit 和Notepad++ 使用ftp直接编辑linux上文件

    安装ftp服务 apt-get install vsftpd 安装完后更改相关配置文件 /etc/vsftpd.conf cp /etc/vsftpd.conf /etc/vsftpd.conf.ol ...

  9. Fragment的简单使用

    最近一直有点忙,刚刚看到一个朋友的留言提到Fragment中加载ListView的问题,这里写了一个非常简单的测试,至于对Fragment的增.删.改实现动态布局构建灵活的UI,以后有时间在讨论: M ...

  10. [RxJS] Displaying Initial Data with StartWith

    You often need to render out data before you stream begins from a click or another user interaction. ...