HDU1019(2028)解题报告

时间:2017-07-31 03:51:55
【文件属性】:

文件名称:HDU1019(2028)解题报告

文件大小:555B

文件格式:CPP

更新时间:2017-07-31 03:51:55

HDU1019 Least Common Multiple

Least Common Multiple 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 题目分析:求n个数的最小公倍数;先利用gcd算法求两个数的最大公约数,再考虑最小公倍数=两数乘积/最大公约数,即可求得最小公倍数。 注意:要考虑到输入的输入的n个数中的0,有0的要去掉0求其他数的最小公倍数。 代码:


网友评论