问题 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 ...
随机推荐
- 解决div+img布局下img下端出现空白的bug
1.将图片转换为块级对象 即设置img为“display:block;”.在本例中添加一组CSS代码:“#sub img {display:block;}”. 2.设置图片的垂直对齐方式 即设置图片的 ...
- Java基础——线程复习总结
线程 T ...
- Spring知识点总结(四)之SpringAOP基础 - 代理设计模式
1. 分析程序中存在的问题(高内聚,低耦合) 通过springIOC DI) 以及注解的使用,成功解决了在程序中层与层之间出现的耦合的问题,但是在很多地方仍然存在非该层应该实现的 ...
- xcode 快捷键大全、XCode常用快捷键图文介绍
其实就是设置里面的快捷键变成了文字版,刚开始用Xcode是不是发现以前熟悉的开发环境的快捷键都不能用了?怎么快捷运行,停止,编辑等等.都不一样了.快速的掌握这些快捷键,能提供开发的效率. 其实快捷键在 ...
- AOJ 0531 坐标离散化
涂色:(日文题目,自己翻译成了中文)为了宣传信息竞赛,要在长方形的三合板上喷油漆来制作招牌.三合板上不需要涂色的部分预先贴好了护板.被护板隔开的区域要涂上不同的颜色,比如上图就应该涂上5种颜色. 请编 ...
- 关于 'list' object has no attribute 'select'
我是在写爬虫是遇到了这个问题: c = chapter.select('href')AttributeError: 'list' object has no attribute 'select' 这是 ...
- 根据坐标计算距离(mysql函数)
CREATE DEFINER=`root`@`localhost` FUNCTION `getDistance`(lng1 ) BEGIN DECLARE result double; DECLARE ...
- ubuntu系统快速搭建开发环境
1.免密登陆 1.1 原理 ssh协议中用到了对称加密和非对称加密,如果不了解可以百度一下,原理引用一下这篇博客 在ssh中,非对称加密被用来在会话初始化阶段为通信双方进行会话密钥的协商.由于非对称加 ...
- Co. - Apple - MacBook Pro 快捷键
Mac 键盘快捷键:https://support.apple.com/zh-cn/HT201236 从windows转到mac的童鞋,可能删除键是心中的一个痛,以前习惯一按delete什么都消失,其 ...
- node 写api几个简单的问题
最近出了一直在做无聊的管理后台,还抽空做了我公司的计费终端,前端vue,后端node,代码层面没啥太多的东西.由于自己node版本是8.0.0,node自身是不支持import和export的,要想基 ...