acm2028

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a736933735/article/details/50095247
/*
 * 求n个数的最小公倍数
 */
import java.util.*;

public class ACM2028 {

    // 最大公约数
    static long gcd(long a, long b) {
        long r = a % b;
        while (r != 0) {
            a = b;
            b = r;
            r = a % b;
        }
        return b;
    }

    // 最小公倍数
    static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            long result = 1;
            for (long i = 0; i < n; i++) {
                long num = in.nextLong();
                result = lcm(result, num);
            }
            System.out.println(result);
        }
    }
}


猜你喜欢

转载自blog.csdn.net/a736933735/article/details/50095247