HDU 1019(n个数的LCM)
来源:互联网 发布:相宜本草淘宝有假货吗 编辑:程序博客网 时间:2024/06/10 13:23
Least Common Multiple
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 54173 Accepted Submission(s): 20643
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
23 5 7 156 4 10296 936 1287 792 1
Sample Output
10510296
//4 6//6 4//4 2//2 0#include <stdio.h>int gcd(int p,int q){while(q!=0){return gcd(q,p%q);}return p;}int main(){int t;scanf("%d",&t);while(t--){int n,x,y,i;scanf("%d%d",&n,&x);for(i=0; i<n-1; i++){scanf("%d",&y);x=x/gcd(x,y)*y;}printf("%d\n",x);}return 0;}
阅读全文
0 0
- HDU 1019(n个数的LCM)
- HDOJ 1019 Least Common Multiple (求n个数的LCM)
- 求N个数的最小公倍数(LCM)
- LightOJ 1024 - Eid (高精度求n个数的LCM)
- hdu(1019)n个数的最小公倍数。。
- hdu 1019 n个数的最小公倍数
- LCM的个数 UVa10892
- LCM的个数
- LCM的个数
- 【SDUT 3275】 LCM的个数
- 求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法
- 求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法
- 求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法
- 求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法
- 求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法
- 求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)的较优算法
- 求两个或N个数的最大公约数(gcd)和最小公倍数(lcm)
- hdu 求n个数的最小公倍数
- #!/usr/bin/env python与#!/usr/bin/python的区别
- vmvare虚拟机的三种网络连接方式(bridged、NAT、Host-only)及区别
- hdu1517A Multiplication Game(bash博弈)
- 2017百度之星总结
- C++学习12:数组array
- HDU 1019(n个数的LCM)
- 全面解析Bootstrap表单使用方法(表单按钮)
- 适配器模式(2)
- Google算法题:三数求和
- 手势监听上下左右
- Ubuntu16.04lTS安装qq文件时在处理时有错误发生:xxxi386问题
- 300. Longest Increasing Subsequence(DP经典问题)
- 利用豆瓣短评数据生成词云
- eclipse 设置默认编码为Utf-8