HDU 1019 (多个数的最小公倍数)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1019
Least Common Multiple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 61592 Accepted Submission(s): 23486
3 5 7 15
6 4 10296 936 1287 792 1
10296
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int gcd(int a,int b)
{
if (b==)
return a;
return gcd(b, a%b);
}
int main()
{
//公式:a,b的最小公倍数等于a,b的乘积除以a,b的最大公约数
//直接暴力即可
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int a=,cnt=;
int x;
for(int i=;i<n;i++)
{
scanf("%d",&x);
cnt=a/gcd(a,x)*x;//先除后乘,避免溢出
a=cnt;
}
printf("%d\n",a);
}
return ;
}
HDU 1019 (多个数的最小公倍数)的更多相关文章
- hdu 1019 n个数的最小公倍数
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- hdu 1788(多个数的最小公倍数)
Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- HDU 1019 Least Common Multiple【gcd+lcm+水+多个数的lcm】
Least Common Multiple Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
- n个数的最小公倍数
Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最小公倍数,每个测 ...
- HDOJ-ACM1019(JAVA) 多个数的最小公倍数
题意:求多个数的最小公倍数 很简单,但是我一开始的做法,估计会让结果越界(超过int的最大值) import java.util.*; import java.io.*; public class M ...
- ACM hdu 1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDU_2028——求多个数的最小公倍数
Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最 ...
- HDU 1019 Least Common Multiple GCD
解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...
随机推荐
- 译:Java局部变量类型推断(Var类型)的26条细则
原文链接:https://dzone.com/articles/var-work-in-progress 作者:Anghel Leonard 译者:沈歌 Java局部变量类型推断(LVTI),简称va ...
- python模块之matplotlib
官方网址:http://matplotlib.org/tutorials/introductory/lifecycle.html#sphx-glr-tutorials-introductory-lif ...
- Linux From Scratch(从零开始构建Linux系统,简称LFS)(三)
九. 系统配置 1. 安装 LFS-Bootscripts-20150222 软件包包含一套在 LFS 系统启动和关闭时的启动和停止脚本. cd /sources tar -jxf lfs-boots ...
- Cardinality Estimation算法学习(一)(了解基数计算的基本概念及回顾求字符串中不重复元素的个数的问题)
最近在菜鸟教程上自学redis.看到Redis HyperLogLog的时候,对“基数”以及其它一些没接触过(或者是忘了)的东西产生了好奇. 于是就去搜了“HyperLogLog”,从而引出了Card ...
- vcfc之zk+postsql+keystore(cassandra)框架分析
vcfc框架总结: 1 一. bus和keystore是如何协调处理的,什么样的问题是处理不了的? 1. 如果在备重启的过程中,主处理了某个时间1,备机如果同步数据呢? 二 .数据可靠性和一致性分析 ...
- Hibernate 注解(Annotations 一)
1. @Entity 将一个类声明为一个实体bean(即一个持久化POJO类). 2. @Table 声明了该实体bean映射指定的表(table),目录(catalog)和schema名字 3. @ ...
- sql:function
--查询权限函数 --1 declare @names varchar(3000) set @names='' select @names=@names+isnull(AdminPermissForm ...
- table中的td自动换行
总有那么几个时候会觉得,table的td不能自适应换行真坑,凭什么只能用tr来换行,经常数据都是连在一起的呀,你叫我怎么把它拆分放到tr里...... 那能不能用ul和li来替换?可以是可以,不过有时 ...
- Codeforces Round #414 A. Bank Robbery
A. Bank Robbery time limit per test 2 seconds memory limit per test 256 megabytes A robber has a ...
- latex 调整间隔
转自:http://blog.sina.com.cn/s/blog_4a4927c70100phsb.html,感谢分享! 一.LATEX调整公式与正文间距离,调整空白大小: 调整空白命令: \s ...