JAVA大数——lightoj1024

要用 System.gc() 清理内存

类必须命名成Main,一些大整数的操作

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int t,n;
        t=cin.nextInt();
        BigInteger ans,m,d;
        for(int tt=1;tt<=t;tt++) {
            n=cin.nextInt();
            m=cin.nextBigInteger();
            ans=m;
            for(int i=1;i<n;i++) {
                m=cin.nextBigInteger();
                d=ans.gcd(m);
                ans=ans.multiply(m).divide(d);
            }
            System.out.println("Case "+tt+": "+ans);
            System.gc();
        }
    }
}

 

posted on 2019-07-04 09:33  zsben  阅读(170)  评论(0编辑  收藏  举报

导航