HDU 1019 Least Common Multiple 数学题解
求一组数据的最小公倍数。
先求公约数在求公倍数。利用公倍数,连续求全部数的公倍数就能够了。
#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 数学题解的更多相关文章
- 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 ...
- HDU - 1019 - Least Common Multiple - 质因数分解
http://acm.hdu.edu.cn/showproblem.php?pid=1019 LCM即各数各质因数的最大值,搞个map乱弄一下就可以了. #include<bits/stdc++ ...
- HDU 1019 Least Common Multiple GCD
解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...
- 背包系列练习及总结(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 ...
- HDU 3092 Least common multiple 01背包
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...
- HDU 4913 Least common multiple
题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
随机推荐
- Linux文件权限与目录
1:文件操作者的身份 owner:创建文件.拥有文件的登录用户. group:同一群组内的用户. others:其他登录用户. [系统账户与密码信息保存在/etc/passwd:个人账户与密码信息保存 ...
- Eclipse项目修改没有同步到编译的问题
有两个原因: 1:项目有错,不能正常编译:查看是否有Jar包冲突.JDK版本问题等: 2:编译输出目录配置错误: Maven项目会修改项目编译时的输出路径到target文件夹,但是我们用Myelips ...
- 怎样使用Fiddler获取WebApi的token值?
User-Agent: Fiddler Host: localhost: Content-Length: Content-Type: application/json grant_type=passw ...
- gitlab webhook报500
使用root登陆gitlab,进入如下位置:
- JS修改当前控件样式&为控件追加事件
先搁这吧,今天太晚了,以后再加注释和修整吧.不幸搜到的朋友就别看了 <%@ Page Language="vb" AutoEventWireup="false&qu ...
- Navicatmysql专版
Navicat是非常牛逼的公司在数据库可视化方面,做出许多工具...,可视化,为了更加人性化的操作,远离枯燥无味的黑色窗口 一睹真容 捐献一枚注册码 注册码:NAVH-WK6A-DMVK-DKW3 D ...
- 转:D3DXVec3TransformNormal() 与 3DXVec3TransformCoord() 的区别
DirectX中有两个很相似的函数,输入与输出的参数格式完全一样,都是输入一个三维向量(D3DXVECTOR3)和一个矩阵(D3DXMATRIX),输出变换之后的向量(D3DXVECTOR3). 函数 ...
- TL 重构
import dependencies.*;import org.apache.commons.lang3.ArrayUtils;import org.apache.commons.lang3.Str ...
- Dockerfile 构建后端tomcat应用并用shell脚本实现jenkins自动构建
Dockerfile 文件构建docker镜像 FROM centos MAINTAINER zhaoweifeng "zh******tech.cn" ENV LANG en_U ...
- 什么样的路由器有类似改hosts的功能
2011-7-22 23:06:45 如题 就是像电脑上改hosts那样把某个域名强制解析到指定IP上 TT,DD和openwrt有没有这样的功能? ------------------------- ...