HDU——1019Least Common Multiple(多个数的最小公倍数)
Least Common Multiple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 42735 Accepted Submission(s): 16055
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.
3 5 7 15
6 4 10296 936 1287 792 1
10296
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long gcd(long long a,long long b)
{
return b?gcd(b,a%b):a;//还是记这个吧,简单易用
}
int main()
{
int t;
cin>>t;
while (t--)
{
int n;
long long a,tlcm,beg=1;//让beg初始化为1不影响结果并成为第0个数,这样一开始也就可以一个一个地求gcd
scanf("%d",&n);
for (int i=0; i<n; i++)
{
scanf("%lld",&a);
beg=(beg*a)/gcd(a,beg);
}
cout<<beg<<endl;
}
return 0;
}
HDU——1019Least Common Multiple(多个数的最小公倍数)的更多相关文章
- 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 ...
- 杭电1019Least Common Multiple
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1019 题目: Problem Description The least common multiple ...
- 杭电1019-Least Common Multiple
#include<stdio.h>int gcd(int a,int b);int main(){ int n,m,a,b,i,sum;//sum是最小公倍数 scanf(&q ...
- 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 ...
- hdu 2028 Lowest Common Multiple Plus(最小公倍数)
Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- hdu_1019Least Common Multiple(最小公倍数)
太简单了...题目都不想贴了 //算n个数的最小公倍数 #include<cstdio> #include<cstring> #include<algorithm> ...
- HDU 3092 Least common multiple 01背包
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...
- HDU 1019 (多个数的最小公倍数)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (J ...
随机推荐
- Webpack 10分钟入门
可以说现在但凡开发Single page application,webpack是一个不可或缺的工具. WebPack可以看做是一个模块加工器,如上图所示.它做的事情是,接受一些输入,经过加工产生一些 ...
- UVA208 Firetruck 消防车(并查集,dfs)
要输出所有路径,又要字典序,dfs最适合了,用并查集判断1和目的地是否连通即可 #include<bits/stdc++.h> using namespace std; ; int p[m ...
- Sequence II
6990: Sequence II 时间限制: 3 Sec 内存限制: 128 MB提交: 206 解决: 23[提交][状态][讨论版][命题人:admin] 题目描述 We define an ...
- 2018.4.1 Ubuntu16.04 下配置Tomcat服务器以及设置dingshi启动
Tomcat自启动的设置技巧 以root用户登录系统: cd /etc/rc.d/init.d/ vi tomcat #!/bin/sh # # tomcat: Start/Stop/Restart ...
- linux目录结构及文件管理
Linux的目录结构: / 根分区 linux文件系统的起点 /bin 普通用户的命令,普通用户能使用 /sbin 管理员使用的命令,只有管理 ...
- DROP INDEX - 删除一个索引
SYNOPSIS DROP INDEX name [, ...] [ CASCADE | RESTRICT ] DESCRIPTION 描述 DROP INDEX 从数据库中删除一个现存的索引. 要执 ...
- perl -p -i -w -e
.txt kllk nciuwbufcbew``````//.]];s[[..; klklkl x,dsncdk,;l,ex xw,eocxmcmck .txt .txt kkkkkkkkkkkkkk ...
- HTML5<nav>元素
HTML5中<nav>元素定义页面导航链接的部分区域,但并不是所有的链接都放到nav元素里面. 实例: <header id="pageHeader"> & ...
- mac 升级EI Capitan后遇到c++转lua时遇到libclang.dylib找不到的错
升级EI Capitan后,打包lua脚本时,会报这个错: LibclangError: dlopen(libclang.dylib, 6): image not found. To provide ...
- oc中将CGRect、CGSize、CGPoint等结构体转换为字符串
CGRect rect = CGRectMake(160, 230, 200, 200); CGPoint point = CGPointMake(20, 20); CGSize size = CG ...