hdu_1019Least Common Multiple(最小公倍数)
太简单了。。。题目都不想贴了
//算n个数的最小公倍数
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int gcd(int a, int b)
{
return b==?a:gcd(b,a%b);
}
int lcm(int a, int b)
{
return a/gcd(a,b)*b;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
int tm = ;
int a;
for(int i = ; i < n; i++){
scanf("%d",&a);
tm = lcm(tm,a);
}
printf("%d\n",tm);
}
return ;
}
![]() |
||||||||||
|
||||||||||
Least Common MultipleTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which is divisible by all the numbers in the set. For example, the LCM of 5, 7 and 15 is 105.
Input
Input will consist of multiple problem instances. The first line of the input will contain a single integer indicating the number of problem instances. Each instance will consist of a single line of the form m n1 n2 n3 ... nm where m is the number of integers in the set and n1 ... nm are the integers. All integers will be positive and lie within the range of a 32-bit integer.
Output
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.
Sample Input
2
3 5 7 15 6 4 10296 936 1287 792 1 Sample Output
105
10296 Source
Recommend
|
||||||||||
|
hdu_1019Least Common Multiple(最小公倍数)的更多相关文章
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- zoj1797 Least Common Multiple 最小公倍数
Least Common Multiple Time Limit: 2 Seconds Memory Limit: 65536 KB The least common multiple (L ...
- Least Common Multiple (最小公倍数,先除再乘)
思路: 求第一个和第二个元素的最小公倍数,然后拿求得的最小公倍数和第三个元素求最小公倍数,继续下去,直到没有元素 注意:通过最大公约数求最小公倍数的时候,先除再乘,避免溢出 #include ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)
也称欧几里得算法 原理: gcd(a,b)=gcd(b,a mod b) 边界条件为 gcd(a,0)=a; 其中mod 为求余 故辗转相除法可简单的表示为: int gcd(int a, int b ...
- HDU - 1019-Least Common Multiple(求最小公倍数(gcd))
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- HDU1019 Least Common Multiple(多个数的最小公倍数)
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- 题目1439:Least Common Multiple(求m个正数的最小公倍数lcm)
题目链接:http://ac.jobdu.com/problem.php?pid=1439 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- (杭电1019 最小公倍数) Least Common Multiple
Least Common Multiple Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
随机推荐
- BSGS离散对数(Baby-Step-Giant-Step)
BSGS离散对数(Baby-Step-Giant-Step) 题目: 给定\(x,y,p,\)求最小的自然数\(k\)满足\(x^k=y(\mod p)\)\(p\le2^{31}\)(满足一定有答案 ...
- JaveScript流程控制(JS知识点归纳四)
01 流程控制 顺序结构: 程序的默认执行方式 条件判断语句:也称之为分支结构,选择结构:如果程序要执行的代码出现了多种情况需要使用 循环结构:当代码需要多次重复执行多次时,使用 02 条件判断语句 ...
- Wincc flexable的IO域组态
1.题目 2.新建三个变量 3.组态画面,添加IO域1 1)常规设置 2)属性设置 4.组态IO域2 1)常规项 2)属性设置 5.组态第三个IO域 1)常规设置 2)属性设置 6.此外可以设置动画 ...
- 如何录屏制作gif图片
LICEcap简介: LICEcap是一款屏幕录制制作gif图片的工具,支持导出 GIF 动画图片格式,轻量级.使用简单,录制过程中可以随意改变录屏范围. LICEcap 直观易用,功能灵活,支持 W ...
- redis咋么实现分布式锁,redis分布式锁的实现方式,redis做分布式锁 积极正义的少年
前言 分布式锁一般有三种实现方式:1. 数据库乐观锁:2. 基于Redis的分布式锁:3. 基于ZooKeeper的分布式锁.本篇博客将介绍第二种方式,基于Redis实现分布式锁.虽然网上已经有各种介 ...
- CentOS 7.x上gitlab搭建教程(https可用,邮件可用)
目录 知识要求 搭建感想 搭建过程 参考 知识要求: nginx基础知识 搭建感想 注:以下是我搭建gitlab时的思考,需要nginx的基础知识,Docker的基础知识才容易理解,与下面的搭建过程是 ...
- Java_Date_01_判断两个时间相差的天数
二.参考资料 1.java 判断两个时间相差的天数 2.java计算两个日期之间相差天数和相隔天数详解
- Oracle学习笔记_10_判断是否为日期类型
FUNCTION isdate (datestr VARCHAR2, format VARCHAR2) RETURN number IS p_date DATE; BEGIN SELECT TO_DA ...
- C语言中static关键字的用法
C记得还是大一时学的,现在觉得好久没用了,又捧起来看看.今天刚看到有关static关键字,仔细地看了一遍<C和指针>这本书中的解释,现在觉得清楚多了. 首先,我们将static关键字,修饰 ...
- Java第二章----对象和类
从第一章到第二章整整隔了一个月的时间,这速度也是慢的无语了.因为这个月负责开发公司一个SaaS类型APP,忙的昏天暗地终于上线了,这才有时间写个博客.本章还是以概念为主,有点枯燥重在理解. 第一节:对 ...