问题 A: Least Common Multiple
题目描述
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 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.
输出
For each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.
样例输入
2
2 3 5
3 4 6 12
样例输出
15
12 题意 有T组数据 每组首先给一个n 然后有n个数 问这个n个数的最小公倍数是多少
#include<bits/stdc++.h> using namespace std;
int gcd(int a,int b)
{
if(b==) return a;
return gcd(b,a%b);
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
int d=;//小技巧 可以把d设置成1
for(int i=;i<n;i++){
int x;
scanf("%d",&x);
d=d/gcd(d,x)*x;//第一次时 gcd=1 这种写法防止溢出
}
printf("%d\n",d);
}
return ;
}
问题 A: Least Common Multiple的更多相关文章
- K - Least Common Multiple
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- [UCSD白板题] Least Common Multiple
Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...
- hdu1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDOJ2028Lowest Common Multiple Plus
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 九度OJ 1056--最大公约数 1439--Least Common Multiple 【辗转相除法】
题目地址:http://ac.jobdu.com/problem.php?pid=1056 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. 输出: 对于每组 ...
- HDU-1019 Least Common Multiple
http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...
- Least Common Multiple
地址:http://www.codewars.com/kata/5259acb16021e9d8a60010af/train/python 题目: Write a function that calc ...
- ACM hdu 1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDOJ 1019 Least Common Multiple(最小公倍数问题)
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
随机推荐
- HDU 1180 诡异的楼梯(超级经典的bfs之一,需多回顾)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1180 诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others) ...
- hadoop 错误
错误:DataXceiver error processing WRITE_BLOCK operation 2014-05-06 15:21:30,378 ERROR org.apache.hadoo ...
- C#基础 一(方法详解)
需要知道:类和方法的关系 方法和参数修饰符 自定义方法可以有或没有参数,也可以有或没有返回值.可以被各种关键字(static.virtual.public.new等)修饰以限制其行为. C#参数修饰符 ...
- ffmpeg一些filter用法、以及一些功能命令
来源:http://blog.csdn.net/dancing_night/article/details/46776903 1.加字幕 命令:ffmpeg -i <input> -fil ...
- sudo cd的错误
问题说明 今天用MySQL建了库,想看看. 当到了这步,心里的第一个感觉就是电脑坏了.后来查了查才知道了原因. 原因 cd不是一个应用程序而是Linux内建的命令,而sudo仅仅只对应用程序起作用. ...
- Element.getBoundingClientRect()
Element.getBoundingClientRect()方法会返回元素的大小和相对于视口的位置 语法: var domRect = element.getBoundingClientRect() ...
- 微信小程序navigator无法跳转情况
情况有三种 跳转的页面没有在app.json中注册 跳转的路径不正确 以上两种在命令行(console)中都会提示 跳转的页面在TabBar中,需要将open-type属性是设置为switchTab
- linux命令之磁盘和文件系统操作
1. fdisk:磁盘分区命令 语法:fdisk [选项][参数] 命令说明:fdisk是linux系统里常用的一种磁盘管理工具,可以创建和管理系统分区 常用命令选项: -l:列出指定的并退出,没 ...
- 23种java设计模式之装饰者模式及动态代理
设计模式不管对于何种语言都是存在的,这里介绍的是java的模式 装饰者模式是在二次开发中应用比较多的一款模式,当然了用反射也是可以实现的,今天介绍的是装饰模式,有兴趣的朋友可以自己去了解一下反射是怎么 ...
- 【poe设备加电配置】
开启接口的poe功能: [interface_name]: 配置poe端口的最大功率: [interface_name[: 配置poe的端口工作模式: [interface_name[: 配置poe端 ...