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 ...
随机推荐
- 用过的关于css的知识
1.代码片段 让两个div并排起来显示. <div style="width:1000px; text-align:center;" id="content&quo ...
- lograted日志切割脚本
root@op-testsetup-web3.idc1.yiducloud.cn:/etc/logrotate.d# cat etcd /home/work/docker/logs/etcd/prev ...
- ArcGIS 网络分析[2.3] 最近设施点
什么是最近设施点? 仍然举一个生动形象例子说明. 我在大街的某一个点儿上,我急需上厕所,问:我3分钟内能到的最近的厕所在哪? 这就是最近设施点分析(ClosestFacility)--给定搜索半径,基 ...
- Docker(六):Docker网络配置进阶
1.Docker集群网络配置之Weave Weave是Github上一个比较热门的Docker容器网络方案,具有非常良好的易用性且功能强大.仓库地址:https://github.com/weavew ...
- css实现一行居中显示,两行靠左显示,超过两行以引号省略
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Java设计模式之(一)------单例模式
1.什么是单例模式? 采取一定的办法保证在整个软件系统中,单例模式确保对于某个类只能存在一个实例.有如下三个特点: ①.单例类只能有一个实例 ②.单例类必须自己创建自己的实例 ③.单例类必须提供外界获 ...
- 【转】java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
最近在配置最新的ssh(struts2.3.16.3+hibernate4.3.7+spring4.1.2)的时候遇到的这个错误提示,后来在网上找了半天都不能解决,虽然有个说法是model对象用这样@ ...
- PHP动态图像处理
相关代码见:https://www.github.com/lozybean/learn_www/ 目录 1. 画布管理: imagecreate():创建一个基于调色板的画布,指定画布的长.宽 ...
- RGB颜色 对照表
来自为知笔记(Wiz)
- CSS中的块级元素(block)与行内元素(inline)
css中有3种基本的定位机制:普通流(相对定位实际上看做普通流定位模型的一部分)浮动(float)绝对定位(固定定位是绝对定位的一种)所以在学习浮动之前,我们先要了解块级元素与内联元素(行内元素).块 ...