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
 #include<bits/stdc++.h>
using namespace std;
long long solve(long long a,long long b)
{
long long m,n,c;
m = a, n = b;
a = max(m,n);
b = min(m,n);
while(b)
{
c = a % b;
a = b;
b = c;
}
return m*n/a;
}
int main()
{
long long T,n,a,b;
while(cin>>T)
{
while(T--)
{
scanf("%d",&n);
scanf("%d",&a);
for(int i = ; i < n-; i++)
{
scanf("%d",&b);
a = solve(a,b);
}
cout<<a<<endl;
}
}
return ;
}

ACM Least Common Multiple的更多相关文章

  1. 2028 ACM Lowest Common Multiple Plus

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2028 思路:最一想到的就是暴力求解,从1开始一直到最后的答案,一直来除以给出的数列的数,直到余数为0:当然 ...

  2. ACM hdu 1019 Least Common Multiple

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

  3. ACM学习历程—HDU 3092 Least common multiple(数论 && 动态规划 && 大数)

    Description Partychen like to do mathematical problems. One day, when he was doing on a least common ...

  4. HDU-1019 Least Common Multiple

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

  5. ACM-简单题之Least Common Multiple——hdu1019

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  6. 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 ...

  7. hdu_1019Least Common Multiple(最小公倍数)

    太简单了...题目都不想贴了 //算n个数的最小公倍数 #include<cstdio> #include<cstring> #include<algorithm> ...

  8. HDU 4913 Least common multiple

    题目:Least common multiple 链接:http://acm.hdu.edu.cn/showproblem.php?pid=4913 题意:有一个集合s,包含x1,x2,...,xn, ...

  9. HDU 3092 Least common multiple 01背包

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3092 Least common multiple Time Limit: 2000/1000 MS ...

随机推荐

  1. SourceTree 01 - git 客户端介绍

    SourceTree - git客户端介绍 SourceTree系列第1篇 --->> SourceTree 01 - git 客户端介绍(http://www.cnblogs.com/g ...

  2. requests+正则表达式提取猫眼电影top100

    #requests+正则表达式提取猫眼电影top100 import requests import re import json from requests.exceptions import Re ...

  3. [ABP]浅谈模块系统与 ABP 框架初始化

    在 ABP 框架当中所有库以及项目都是以模块的形式存在,所有模块都是继承自AbpModule 这个抽象基类,每个模块都拥有四个生命周期.分别是: PreInitialze(); Initialize( ...

  4. 机器学习基石:10 Logistic Regression

    线性分类中的是非题------>概率题, 设置概率阈值后,大于等于该值的为O,小于改值的为X.------>逻辑回归. O为1,X为0: 逻辑回归假设: 逻辑函数/S型函数:光滑,单调, ...

  5. codefroces 612E Square Root of Permutation

    A permutation of length n is an array containing each integer from 1 to n exactly once. For example, ...

  6. 【BZOJ2809】【APIO2012】派遣

    Background 在一个忍者的帮派里,一些忍者们被选中派遣给顾客,然后依据自己的工作获取报偿. Description 在这个帮派里,有一名忍者被称之为Master.除了Master以外,每名忍者 ...

  7. Codeforces Round #404 (Div. 2)

    好久没打CF了,打场div2练手.因为比较晚还没提前睡有点神志不清,E题打了莫名其妙的代码调了好久,最后结束后5分钟才发现哪里错了-- AC:ABCD Rank:60 A.Anton and Poly ...

  8. hdu 4267 线段树间隔更新

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. ESLint规范

    配置如下:{ // 环境定义了预定义的全局变量. "env": { //环境定义了预定义的全局变量.更多在官网查看 "browser":true, " ...

  10. C++ 二分法求解方程的解

    二分法是一种求解方程近似根的方法.对于一个函数 f(x)f(x),使用二分法求 f(x)f(x) 近似解的时候,我们先设定一个迭代区间(在这个题目上,我们之后给出了的两个初值决定的区间 [-20,20 ...