问题 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 ...
随机推荐
- 【洛谷P1083】[NOIP2012]借教室
借教室 [题目描述] 在n天中每天有一个可以借出的教室数,有m个订单,每个订单从第l天到第r天要借用x个教室.问能否满足所有的订单,若不能,输出第一个不能满足的订单编号. 思路: 1.1 ≤ n,m ...
- python 通过 socket 发送文件
目录结构: client: #!/usr/bin/env python # -*-coding:utf-8 -*- import socket, struct, json download_dir = ...
- SQL数据完整性
1.数据的完整性 1. 什么是数据的完整性 保证用户输入的数据保存到数据库中是正确的 2.添加数据完整性 在创建表的时候给表添加约束 3.完整性分类 实体完整性.域完整性.引用完整性 2.完整 ...
- Extjs treePanel 的treestore重复加载问题解决
在Extjs 4.2.2 中构建一个treePanel 发现设置rootVisible后 ,treeStore中设置的autoLoad:false不启作用,在组件初始化的时候即加载数据源,造成数据重复 ...
- Python基础—05-总结:双重循环,数据类型
总结 双重循环 冒泡排序 lt = [1, 5, 7, 3, 2, 4] # 计算元素的个数 n = len(lt) # 外层循环控制圈数 for i in range(n-1): for j in ...
- c#实现的HTTP服务端
这次在整理一个服务组件的时候,需要涉及到HTTP的请求,HTTP是应用层,建立在TCP之上的.因此,可以用TCP服务端接收HTTP请求,只需要解析请求内容.HTPP有固定的格式,大家可以直接搜索.网上 ...
- Ajax 跨域的几种解决方案
作者:黄轩链接:http://www.zhihu.com/question/19618769/answer/38934786来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处 ...
- PP: 混合生产方式(MTO与MTS为例)(转)
http://blog.sina.com.cn/s/blog_4c01b7650100yf1d.html PP: 混合生产方式(MTO与MTS为例) 一.业务概览某公司生产的同一种产品正常情况下客户无 ...
- windows10安装mysql8.0.11(免安装版)
1.MySQL8.0.11下载网址:https://dev.mysql.com/downloads/mysql/ 2.配置环境变量:我的电脑->属性->高级系统设置->环境变量-&g ...
- Ajax在表单中的应用
ajax在注册用户表单中的使用 1.验证用户名是否被使用 2.获取手机短信验证码 3.点击表单中的图片刷新,可实现刷新图片验证码 <!DOCTYPE html> <html> ...