[暑假集训--数论]hdu1019 Least Common Multiple
2024-08-29 18:02:34
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.
InputInput 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.
OutputFor each problem instance, output a single line containing the corresponding LCM. All results will lie in the range of a 32-bit integer.
Sample Input
2
3 5 7 15
6 4 10296 936 1287 792 1
Sample Output
105
10296
a*b=gcd(a,b)*lcm(a,b)
lcm(a,b)=a*b/gcd(a,b)
求n个数的lcm,每加一个数进去就ans=ans/__gcd(ans,x)*x
除法放中间是为了防爆int
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int T;
int main()
{
T=read();
for (int i=;i<=T;i++)
{
int x=read(),now=read(),y;
for (int i=;i<=x;i++)
{
y=read();
now=now/__gcd(now,y)*y;
}
printf("%d\n",now);
}
}
hdu 1019
最新文章
- 你想要了解但是却羞于发问的有关SSL的一切
- information_schema系列五(表,触发器,视图,存储过程和函数)
- AngularJS结构简介
- HDU 4971 (最小割)
- Python新手学习基础之数据类型——数字类型
- mysql 事务控制
- UNIX网络编程——客户/服务器程序设计示范(六)
- 【sed】增加一列【shell文本处理】
- Reids 持久化AOF 重写实现原理
- 第二周工作总结——NWNU李泓毅
- PHP之位运算符
- Redhat 用代理连外网
- less的入门教程
- Android短信监听实现,及Android4.4之后短信机制变更
- keras tensorboard的使用
- echarts展示箱型图&;正态分布曲线
- redux中的compose源码分析
- Python 傅里叶分析
- python取当前时间前后一定间隔的时间点
- 转:一步一步学ROP之linux_x86篇 - 蒸米
热门文章
- Java代码工具箱之控制台输出重定向_控制台输出到文件
- 阿里云服务器下安装LAMP环境(CentOS Linux 6.3)(1)
- JDBC开发,数据库的连接
- java基础面试题:java中实现多态的机制是什么?
- Oracle数据库学习(一)
- MySQL - GROUP_CONCAT 使用方法
- 【原创】大数据量时生成DataFrame避免使用效率低的append方法
- 二十九、MySQL 序列使用
- ES6箭头函数基本用法
- hibernate的get() load() 和find()区别