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. 无法安装64位office,因为已有32位版本怎么办

  2. cmd pyhton

    在cmd中运行python解释器: 1.同时执行多条指令,可在多条指令中间使用 & 连接 >>> print('123') &print('223') 123 223

  3. JAVA对象与内存控制

    1.1 实例变量和类变量 成员变量和局部变量: 局部变量分为三大类: 1)形参:在方法签名中定义的局部变量,由方法调用者为其赋值,随方法的结束而消亡. 2)方法内的局部变量:在方法内定义的局部变量,随 ...

  4. Java基础知识强化之集合框架笔记77:ConcurrentHashMap之 ConcurrentHashMap的基本操作

    1. ConcurrentHashMap的初始化: 下面我们来结合源代码来具体分析一下ConcurrentHashMap的实现,先看下初始化方法: public ConcurrentHashMap(i ...

  5. fiddler常用功能一

    fiddler备忘,好久不用,有些步骤忘记了 1.本机pc,目前ie和chrome都可以直接抓取,但是搜狗浏览器暂时抓不到 2.手机端抓包 (1)设置下代理:fiddler客户端查看下端口,然后在手机 ...

  6. toad调用存储过程,存储过程调用sql 类

    1.定义一个sql 类Hello DROP JAVA SOURCE NEWXZXT."Hello"; CREATE OR REPLACE AND RESOLVE JAVA SOUR ...

  7. H.264的码率控制:CBR和VBR

    CBR: Constants Bits Rate, 静态比特率. 比特率在流的进行过程中基本保持恒定并且接近目标比特率,当对复杂内容编码时质量会下降. 在流式播放方案中使用CBR编码最为有效;优点是带 ...

  8. 精读 SBAR SDN flow-Based monitoring and Application Recognition

    目录 架构 测量模块 分类模块 具体实现 实验:最后接入巴塞罗那的校园网流量测试: SBAR: SDN flow-Based monitoring and Application Recognitio ...

  9. .net core 实践笔记(三)--封装底层

    前言: 有了前面的工作,简单的架子基本搭建起来了,因为条件有限,只能先测试SqlServer的了,源码放出来,也希望有兴趣的伙伴可以一起改善,相信可以成为未来进阶架构师的第一步,自己有小项目的时候可以 ...

  10. JDBC—执行sql语句的通用方法

    /* * 执行 sql的方法集 * delete,insert into ,update */ public static void update(String sql){ Connection co ...