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

[暑假集训--数论]hdu1019 Least Common Multiple的更多相关文章

  1. hdu1019 Least Common Multiple

    Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...

  2. HDU-1019 Least Common Multiple

    http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (Java/ ...

  3. HDU1019 Least Common Multiple(多个数的最小公倍数)

    The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...

  4. [暑假集训--数论]poj2773 Happy 2006

    Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD ...

  5. [暑假集训--数论]poj2034 Anti-prime Sequences

    Given a sequence of consecutive integers n,n+1,n+2,...,m, an anti-prime sequence is a rearrangement ...

  6. [暑假集训--数论]hdu2136 Largest prime factor

    Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...

  7. [暑假集训--数论]poj2115 C Looooops

    A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != ...

  8. [暑假集训--数论]poj1365 Prime Land

    Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...

  9. [暑假集训--数论]poj1595 Prime Cuts

    A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...

随机推荐

  1. MySql-8.0.12 安装教程随笔

    下载地址: https://www.mysql.com/downloads/ 现在最下边的社区版本,也就是免费版本 之后我们会看到有两个选择的下载,一个为zip压缩包格式,一个是Install版本,个 ...

  2. 安装配置JDK1.8开发环境以及配置java环境变量的步骤

    1.安装JDK开发环境 下载网站:http://www.oracle.com/ 开始安装JDK: 修改安装目录如下: 确定之后,单击“下一步”. 注:当提示安装JRE时,可以选择不要安装. 2.配置环 ...

  3. LeetCode955删列造序 ||

    问题:删列造序 || 给定由 N 个小写字母字符串组成的数组 A,其中每个字符串长度相等. 选取一个删除索引序列,对于 A 中的每个字符串,删除对应每个索引处的字符. 比如,有 A = [" ...

  4. linux 的安装

    3linux 软件安装 3.1 vm ware 软件安装 双击VMware-workstation-full-10.0.2-1744117.1398244508.exe 单击下一步 单击下一步 选择典 ...

  5. 二叉树(dfs)

    样例输入: 5        //下面n行每行有两个数 2 3    //第i行的两个数,代表编号为i的节点所连接的两个左右儿子的编号. 4 5 0 0    // 0 表示无 0 0 0 0   样 ...

  6. kuangbin 最短路集合

    Til the Cows Come Home poj-2387 #include<iostream> #include<cstdio> #include<algorith ...

  7. [BZOJ1597][Usaco2008 Mar]土地购买(斜率优化)

    Description 农夫John准备扩大他的农场,他正在考虑N (1 <= N <= 50,000) 块长方形的土地. 每块土地的长宽满足(1 <= 宽 <= 1,000, ...

  8. 51nod 1267二分+优化试验场

    最初,最开始的时候,万能的学姐曾经警告过我们,千万别用什么老狮子MAP,手撸map或者字典树...当时不甚理解...今天...这题直接卡掉了我的MAP,但是使用朴素方法进行二分...不加优化,,都不需 ...

  9. 第 8 章: 模块, 包与分发---Word

    第八章: 模块, 包 与 分发 描述: 大型Python程序以模块和包的形式组织.另外,Python标准库中包含大量模块.本章详细介绍模块和包系统.还将提供有关如何安装第三方模块和分发源代码的信息. ...

  10. Kubernetes添加带Quota限额的CephFS StorageClass

    1. 在Ceph上为Kubernetes创建一个文件系统 # ceph osd pool create cephfs_data # ceph osd pool create cephfs_metada ...