Problem Description
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.
 
Input
Input 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.
 
Output
For 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
-------------------------------------------------------------------------------------------
两个数的乘积等于这两个数的最大公约数与最小公倍数的积。
 
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int gcd(int a, int b);
int main()
{
int row, N, ans, b; scanf("%d", &row);
while (row)
{
scanf("%d%d", &N, &ans);
for (int i = 0; i < N - 1; i++)
{
scanf("%d", &b);
//两个数的乘积等于这两个数的最大公约数与最小公倍数的积,先除再乘防止越界。
ans = ans / gcd(ans, b) * b;
}
printf("%d\n", ans);
row--;
}
return 0;
} int gcd(int a, int b)
{
return b ? gcd(b, a%b) : a;
}

  

ACM1019:Least Common Multiple的更多相关文章

  1. 【九度OJ】题目1439:Least Common Multiple 解题报告

    [九度OJ]题目1439:Least Common Multiple 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1439 ...

  2. 题目1439:Least Common Multiple(求m个正数的最小公倍数lcm)

    题目链接:http://ac.jobdu.com/problem.php?pid=1439 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...

  3. HDU2028:Lowest Common Multiple Plus

    Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最小公倍数 ...

  4. HDU 4913 Least common multiple

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

  5. hdoj-2028-Lowest common multiple plus

    题目:Lowest common multiple plus 代码: #include<stdio.h> int common(int a,int b)//计算最大公约数 { int c= ...

  6. 最大公约数最小公倍数 (例:HDU2028 Lowest Common Multiple Plus)

    也称欧几里得算法 原理: gcd(a,b)=gcd(b,a mod b) 边界条件为 gcd(a,0)=a; 其中mod 为求余 故辗转相除法可简单的表示为: int gcd(int a, int b ...

  7. HDOJ2028Lowest Common Multiple Plus

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  8. hdu 2028 Lowest Common Multiple Plus(最小公倍数)

    Lowest Common Multiple Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  9. 九度OJ 1056--最大公约数 1439--Least Common Multiple 【辗转相除法】

    题目地址:http://ac.jobdu.com/problem.php?pid=1056 题目描述: 输入两个正整数,求其最大公约数. 输入: 测试数据有多组,每组输入两个正整数. 输出: 对于每组 ...

随机推荐

  1. 软件磁盘阵列 (Software RAID)

    什么是 RAID 磁盘阵列全名是『 Redundant Arrays of Inexpensive Disks, RAID 』,容错式廉价磁盘阵列. RAID 可以通过一些技术(软件或硬件),将多个较 ...

  2. Linux 硬件RAID详解系统功能图

    RAID-0(条带模式) 特点: 在读写的时候可以实现并发,所以相对其读写性能最好,每个磁盘都保存了完整数据的一部分,读取也采用并行方式,磁盘数量越多,读取和写入速度越快. 因为没有冗余,一个硬盘坏掉 ...

  3. 期末作品项目+ppt+设计文档,电子商城的实现,PC+IOS

    先透露几张图 ---- 可以作为文档模板来用... 下载地址 https://dev.tencent.com/u/whuanle/p/IOS_work/attachment/4563020

  4. December 11th 2016 Week 51st Sunday

    If a thing is worth doing it is worth doing well. 如果事情值得做,那就做好. If it is worth doing, then it is wor ...

  5. jq弹框 (1)内容自适应宽度 2(内容框显示,几秒后自动消失)

      <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&q ...

  6. gluoncv 用已经训练好的模型参数,检测物体

    当然这个模型参数,最好用自己的,否则不够精确,我自己的还没训练完. from matplotlib import pyplot as plt import gluoncv from gluoncv i ...

  7. Vue动态实现评分效果

    1.图片分为三种 on:half:  off <style> .star{ font-size: 0; } .star-item{ display: inline-block; backg ...

  8. 【webpack】config/index.js

    // see http://vuejs-templates.github.io/webpack for documentation. var path = require('path') module ...

  9. Linux中PATH环境变量的作用和使用方法

    关于PATH的作用:PATH说简单点就是一个字符串变量,当输入命令的时候LINUX会去查找PATH里面记录的路径.比如在根目录/下可以输入命令ls,在/usr目录下也可以输入ls,但其实ls这个命令根 ...

  10. linux下搭建LAMP

    PHP命令找不到:  export PATH=$PATH:/usr/local/php/bin https://www.centos.bz/forum/thread-69-1-1.html 步骤: w ...