hdu 1019 n个数的最小公倍数
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
题目的意思:有多组测试,每组有n个数,求这n个数的最小公倍数;
代码:
- #include <iostream>
- using namespace std;
- long long n,m,i,j,k,a;
- int main() {
- cin>>n;
- while(n--){
- cin>>m;
- cin>>k;m=m-1;
- while(m--)
- {
- cin>>a;
- j=k*a;
- while(k!=0)
- {
- i=a%k;
- a=k;
- k=i;
- }
- k=j/a;
- }
- cout<<k<<endl;
- }
- return 0;
- }
思想是:是求两个数的最小公倍数延伸;比如现在有三个数,a,b,c;先求出a和b的最小公倍数d;然后再求d和a的最小公倍数e;e就是a,b,c的最小公倍数;
hdu 1019 n个数的最小公倍数的更多相关文章
- hdu 1788(多个数的最小公倍数)
Chinese remainder theorem again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 ...
- HDU 1019 (多个数的最小公倍数)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1019 Least Common Multiple Time Limit: 2000/1000 MS (J ...
- 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 ...
- Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】
Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...
- n个数的最小公倍数
Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最小公倍数,每个测 ...
- HDOJ-ACM1019(JAVA) 多个数的最小公倍数
题意:求多个数的最小公倍数 很简单,但是我一开始的做法,估计会让结果越界(超过int的最大值) import java.util.*; import java.io.*; public class M ...
- ACM hdu 1019 Least Common Multiple
Problem Description The least common multiple (LCM) of a set of positive integers is the smallest po ...
- HDU_2028——求多个数的最小公倍数
Problem Description 求n个数的最小公倍数. Input 输入包含多个测试实例,每个测试实例的开始是一个正整数n,然后是n个正整数. Output 为每组测试数据输出它们的最 ...
- HDU 1019 Least Common Multiple GCD
解题报告:求多个数的最小公倍数,其实还是一样,只需要一个一个求就行了,先将答案初始化为1,然后让这个数依次跟其他的每个数进行求最小公倍数,最后求出来的就是所有的数的最小公倍数.也就是多次GCD. #i ...
随机推荐
- [BZOJ3561] DZY Loves Math VI
(14.10.28改) 本来只想写BZOJ3739:DZY Loves Math VIII的,不过因为和VI有关系,而且也没别人写过VI的题解,那么写下. 不过我还不会插公式…… http://www ...
- 记录一下最近开发web移动前端的过程
两个项目 第一个是公司网站的移动端,我所在的公司是做某方面的新闻站的. 所以说页面基本是以一条条的新闻+图文混排为主,顶部有一个自动slider+触屏滑动的功能, 使用的是swipe插件,轻量,简洁非 ...
- win7下安装搭建PHP环境
由于最近新找的工作要求php,所以在电脑上安装搭建了PHP环境.主要参考了这篇文章http://www.leapsoul.cn/?p=695(之前第一次搭建时由于版本问题没有弄好) 1.先装apach ...
- 分享一个js生成二维码的库
二维码用js生成会比用服务器生成方便很多,只要把window.location.href的值传入,即可生成对应的二维码..最主要是,这个库可以兼容ie6~ie9哦... 具体使用,请看官网:http: ...
- Python新手学习基础之循环结构练习
有几个元音字母? 有一个字符串"I learn Python from maya",我们想要查找出它里面的元音字母(aeiou)(其实是找出这几个小写字母),并统计出其元音字符的个 ...
- Sphinx编译docs文档
在使用Python.Django的过程中,经常看到docs目录,里面存放着一些txt文本文件,也就是自带的一些帮助文档,里面有make.bat,在dos目录下直接执行make,给出的帮助是可以转换成H ...
- NSNumber与NSInteger的区别 -bei
基本类型,如同C 语言中的 int 类型一样,拿来就可以直接用. 而类在使用时,必须先创建一个对象,再为对象分配空间,接着做初始化和赋值. 类的初始化,需用类自身的方法 (类方法). 代码中所创建的对 ...
- layout_gravity与gravity的区别
1:android:gravity 这个是针对控件里的元素来说的,用来控制元素在该控件里的显示位置. 2:android:layout_gravity 这个是针对控件本身而言,用来控制该控件在包含该控 ...
- 使用 ExpandableListView 实现折叠ListView
1:layout/expandablelistview_groups.xml 标题文件 <?xml version="1.0" encoding="utf-8&qu ...
- 这样就算会了PHP么?-2
学些关于函数FUNCTION方面的东东.. 感觉和PYTHON的APLLY功能差不多.. <?php function come(){ echo "来啦<p>"; ...