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. redis下的持久化保存

    rdb.h   rdb.c  --->  完成数据保存到临时文件,再利用rename保存到指定文件的过程: 如果需要写一个数据持久化保存的功能时,可以参考这部分代码: //rdb API int ...

  2. c++计算器后续(2)

    自娱自乐: 大概是了解了一下前缀.中缀.后缀表示法是啥,并没有去深究,比如考虑实现啊,然后Calculation类里面的计算方法还是选用原来的直接对中缀表达式求值,只是把代码改得规范点,以上. 各表示 ...

  3. IOS Charles(代理服务器软件,可以用来拦截网络请求)

    什么是Charles Charles是一款代理服务器软件,可以用来拦截网络请求 利用Charles能得知大部分公司app的数据来源和数据格式 下载地址:http://www.charlesproxy. ...

  4. Angular2 *ngFor把数据显示在多个input中出错解决方法

    点击添加按钮会自动添加一个空的input组 html <div class="form-inline"> <label class="form-cont ...

  5. svg压缩工具svgo安装使用

    svgo是基于node.js的插件,所以需要先安装node.js 1.安装完node.js后,打开node.js命令窗口,输入npm install -g svgo,安装成后会出现下边的内容 2.对s ...

  6. 2、Android-UI(常用控件)

    2.1.如何编写程序页面 Android中有许多编写程序的方式可供选择 Android Studio和Eclipse中都提供了响应的可视化编辑器 可以直接再进行拖动创建布局 推荐使用手动编写方式进行开 ...

  7. 淡说Linux 的发展史

    ♦ 1  Linux的简单介绍 Linux与Windows一样都是一套OS(操作系统),Windows界面美观 ,普通用户很容易上手,点点鼠标就能搞定许多操作,而Linux生下来就是为程序员的,故精通 ...

  8. Mac安装软件时提示已损坏的解决方法

    问题描述 最近安装从网上下载的软件,安装完之后打开提示xxx已损坏,打不开,软件无法打开. 其实,这是新系统(macOS Sierra 10.12.X)新安全机制的锅,它默认不允许用户自行下载安装应用 ...

  9. Python自动化之Django中间件

    django中间件 Django请求生命周期 中间件中可以定义方法,分别是 process_request(self,request) process_view(self, request, call ...

  10. php json格式化输出

    1.json格式是适用于多种语言的数据格式,通用性高 2.在php中将array格式的数据转化为json格式 3.默认情况下转化后的json格式为一个串,需要将这个串格式化成相应的样式输出 主要的函数 ...