要用 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(); } } }