求一组数据的最小公倍数。

先求公约数在求公倍数。利用公倍数,连续求全部数的公倍数就能够了。

#include <stdio.h>
int GCD(int a, int b)
{
return b? GCD(b, a%b) : a;
} inline int LCM(int a, int b)
{
return a / GCD(a, b) * b;
} int main()
{
int T, m, a, b;
scanf("%d", &T);
while (T--)
{
scanf("%d %d", &m, &a);
while (--m)
{
scanf("%d", &b);
a = LCM(a, b);
}
printf("%d\n", a);
}
return 0;
}

HDU 1019 Least Common Multiple 数学题解的更多相关文章

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

  2. ACM hdu 1019 Least Common Multiple

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

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

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

  4. HDU 1019 Least Common Multiple GCD

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

  5. 背包系列练习及总结(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 ...

  6. HDU 3092 Least common multiple 01背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...

  7. HDU 4913 Least common multiple

    题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...

  8. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

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

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

随机推荐

  1. Linux文件压缩、打包、备份

    1:Linux常见的压缩文件 2:gzip压缩指令 3:bzip2压缩指令(比gzip更高压缩比) 同理,可以用bzcat\bzmore\bzless读取被压缩后文件内容. 4:xz压缩指令(比bzi ...

  2. django之创建第10-1个项目-图片上传并记录上传时间

    1.百度云盘:django之创建第10-1个项目-图片上传并记录上传时间 2.主要修改的配置文件有3个,forms.views和models3个文件以及html 3.forms.py文件修改 #cod ...

  3. 基于py3和pymysql的数据库查询,查询某几列的数据

    #python3 #xiaodeng #基于py3和pymysql的数据库查询,查询某几列的数据 import pymysql conn=pymysql.connect(....) cur=conn. ...

  4. android手机导入.cer证书文件的方法

    访问很多https协议的网站需要安装证书,手机也可以导入cer文件,你知道么?本文将通过简单的两步告诉你手机安装cer文件的方法. 步骤一:请先将数字证书文件“******.cer”文件复制到SD卡的 ...

  5. pycharm安装提示 module 'pip' has no attribute 'main'

    问题描述: 环境: windows10 pycharm2016.2.3  //在最先版本的pycharm就没问题,可能还需要升级pip版本 python3.6 pip安装模块,提示 Attribute ...

  6. HighStock如何动态添加数据组

    var charts = null;        $(function () {            var seriesIds = [830];            // Create the ...

  7. Node.js相关——package概念及NPM

    1. package 包 CommonJS的包规范允许我们将一组相关的模块组合到一起,形成一组完整的工具.CommonJS的包规范由 包结构 和 包描述文件 两个部分组成. 1.1 包结构 包实际上就 ...

  8. ios中radiobutton

    #import <UIKit/UIKit.h> @protocol RadioButtonExtDelegate; @interface RadioButtonExt : UIView - ...

  9. ios中NSObject分类(2)

    #import <Foundation/Foundation.h> UIColor * rgb(int r, int g, int b); UIColor * rgbA(int r, in ...

  10. ios中开始页面做法

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launc ...