LightOJ1024-Eid-大数

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sdz20172133/article/details/88741931

In a strange planet there are n races. They are completely different as well as their food habits. Each race has a food-eating period. That means the ith race eats after every xi de-sec (de-sec is the unit they use for counting time and it is used for both singular and plural). And at that particular de-sec they pass the whole day eating.

The planet declared the de-sec as ‘Eid’ in which all the races eat together.

Now given the eating period for every race you have to find the number of de-sec between two consecutive Eids.

Input 
Input starts with an integer T (≤ 225), denoting the number of test cases.

Each case of input will contain an integer n (2 ≤ n ≤ 1000) in a single line. The next line will contain n integers separated by spaces. The ith integer of this line will denote the eating period for the ith race. These integers will be between 1 and 10000.

Output 
For each case of input you should print a line containing the case number and the number of de-sec between two consecutive Eids. Check the sample input and output for more details. The result can be big. So, use big integer calculations.

Sample Input 


2 20 10 

5 6 30 60 
Sample Output 
Case 1: 20 
Case 2: 60
-

题意:

n个数的最小公倍数

分析:

java大数实现即可

神奇的发现System.gc();//这个不超内存

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

 
public class Main {
 
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T=in.nextInt();
		int cas=0;
		while(T-->0)
		{
			cas++;
			int n = in.nextInt();
			
			BigInteger ans=in.nextBigInteger();
			for(int i=1;i<n;i++)
			{
				BigInteger a=in.nextBigInteger();
				ans=ans.multiply(a).divide(ans.gcd(a));
			}
			System.out.println("Case "+cas+": "+ans);
			System.gc();//这个不超内存
		}
		
		
	}
 
}

猜你喜欢

转载自blog.csdn.net/sdz20172133/article/details/88741931