poj 3101

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

public class POJ_3101 {

	
	public static void main(String[] args) {
		
		Scanner scan =  new Scanner(System.in);
		
		int n = scan.nextInt();
		
		int t[] = new int[n];
		int s[] = new int[10010];
		int count = 0;
		
		for(int i=0;i<n;i++){
			int a = scan.nextInt();
			if(s[a]==0){
				t[count++] = a;
				s[a] = 1;
			}
		}
		
		java.util.Arrays.sort(t,0,count);  //按 运行一圈的时间 进行排序 最后一个 即是 速度最慢的那一个
		
		
		BigInteger[] tm = new BigInteger[count];   //存放分子
		BigInteger[] tmp = new BigInteger[count];  //存放分母
		
		for(int i=0;i<count-1;i++){                //固定最后一个速度 最慢的  求其它与这个的速度差
			tm[i] = BigInteger.valueOf(t[count-1]*t[i]);	//   v =  (1/t[i])-(1/t[count-1])  速度 差
			tmp[i] = BigInteger.valueOf((t[count-1]-t[i])*2);  // (1/v)/2   追到一半的所用的时间  
			BigInteger a = tm[i].gcd(tmp[i]);               // 对得到的分数进行约分   此步一定要做!!
			tm[i] = tm[i].divide(a);
			tmp[i] = tmp[i].divide(a);
		}
		
		count--;
		
		BigInteger lcm = nLCM(tm,count-1);    //求count个数的最小公倍数
		BigInteger gcd = nGCD(tmp,count-1);   //求count个数的最小公约数
		
		System.out.println(lcm+" "+gcd);

	}

	public static BigInteger nGCD(BigInteger[] tmp,int n) {
		
		if(n == 0)
			return tmp[0];
		
		return tmp[n].gcd(nGCD(tmp,n-1));
	}


	public static BigInteger nLCM(BigInteger[] tm,int n) {
		
		if(n == 0)
			return tm[0];
		BigInteger a = nLCM(tm,n-1);
		return tm[n].multiply(a).divide(tm[n].gcd(a));
	}

}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值