LightOJ

来源:互联网 发布:淘宝上的黑科技 编辑:程序博客网 时间:2024/06/11 05:49

题意: 找 n 个数的最小 公倍数


思路:n个数的最小公倍数等于 前n-1个数的最小公倍数 和第n个数的最小公倍数

每给一个数,求他们的最小公倍数,最后结果就是答案,,求a, b最小公倍数 : lcm = a * b / gcd(a, b);

 此题需要高精度


 package program;// by lxkimport java.util.*;import java.math.*;import java.io.*;public class Main {public static void main(String[] args) {Scanner in = new Scanner(System.in);int T = in.nextInt();for(int t = 1; t <= T; ++t) {int n = in.nextInt();System.out.print("Case " + t + ": ");BigInteger ans = in.nextBigInteger();for(int i = 1; i < n; ++i) {BigInteger x = in.nextBigInteger();//BigInteger g = ans.gcd(x);ans = ans.multiply(x).divide(ans.gcd(x));}System.out.println(ans);System.gc();}}}


原创粉丝点击