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

最新文章

  1. 你想要了解但是却羞于发问的有关SSL的一切
  2. information_schema系列五(表,触发器,视图,存储过程和函数)
  3. AngularJS结构简介
  4. HDU 4971 (最小割)
  5. Python新手学习基础之数据类型——数字类型
  6. mysql 事务控制
  7. UNIX网络编程——客户/服务器程序设计示范(六)
  8. 【sed】增加一列【shell文本处理】
  9. Reids 持久化AOF 重写实现原理
  10. 第二周工作总结——NWNU李泓毅
  11. PHP之位运算符
  12. Redhat 用代理连外网
  13. less的入门教程
  14. Android短信监听实现,及Android4.4之后短信机制变更
  15. keras tensorboard的使用
  16. echarts展示箱型图&amp;正态分布曲线
  17. redux中的compose源码分析
  18. Python 傅里叶分析
  19. python取当前时间前后一定间隔的时间点
  20. 转:一步一步学ROP之linux_x86篇 - 蒸米

热门文章

  1. Java代码工具箱之控制台输出重定向_控制台输出到文件
  2. 阿里云服务器下安装LAMP环境(CentOS Linux 6.3)(1)
  3. JDBC开发,数据库的连接
  4. java基础面试题:java中实现多态的机制是什么?
  5. Oracle数据库学习(一)
  6. MySQL - GROUP_CONCAT 使用方法
  7. 【原创】大数据量时生成DataFrame避免使用效率低的append方法
  8. 二十九、MySQL 序列使用
  9. ES6箭头函数基本用法
  10. hibernate的get() load() 和find()区别