Astronomy poj 3101 数论 分数的最小公倍数 Cherish the memory of my broken heart

Astronomy
Time Limit: 2000MSMemory Limit: 65536K
Total Submissions: 4565Accepted: 978

Description

There are n planets in the planetary system of star X. They orbit star X in circular orbits located in the same plane. Their tangent velocities are constant. Directions of orbiting of all planets are the same.

Sometimes the event happens in this planetary system which is called planet parade. It is the moment when all planets and star X are located on the same straight line.

Your task is to find the length of the time interval between two consecutive planet parades.

Input

The first line of the input file contains n — the number of planets (2 ≤ n ≤ 1 000).

Second line contains n integer numbers ti — the orbiting periods of planets (1 ≤ ti ≤ 10 000). Not all of ti are the same.

Output

Output the answer as a common irreducible fraction, separate numerator and denominator by a space.

Sample Input

3
6 2 3

Sample Output

3 1

Hint

Source

Northeastern Europe 2005 , Northern Subregion
 
 
 
唉,我做这个题目做了很久,不能不说在情绪极其不稳定的时候做题是很痛苦的,这时候我真的很想说  If you live to be 100,I hope I live to be 100 minus one day,so I never have to live without  you,但是我没有chance  anymore,又只能好好学习了,三天的时间感觉特别难熬,但是也挺过来了,不废不立,不亡不存..
 
 
不过我觉得这个题目真是很不错哎,它的题意是说啥时候可以让所有的星星都在同一条线上,假如说时间为 t 可以做到,t/x1-t/x2=1/2,这样一转化就是x1*x2/((x1-x2)*2)了,而且这些数都很大的,所以要用到大数相乘的知识,但是我们用java就可以简单的解决这个问题了,我们先找出一组数列中最大的那个数据,因为我们要求出的数分数形式的,我们要求出我们分子上面的最小公倍数,和分母的最大公约数,反正我们最后都是要化简的,而当我们要求出最小公倍数就能保证它能容纳所有的x1*xn的乘积了,好好理解,反正就是这么要求的呗!!!!!
 
 
import java.io.BufferedReader;
import java.math.BigInteger;
import java.util.Scanner;

public class Main3 {

	static Scanner cin = new Scanner(System.in);
	public static void main(String[] args) {
	
		 int[] a=new int[1010];
		 int Max=-1,i;
		 int pos1=-1;
		 int pos2=-2;
		 int n=cin.nextInt();
		 
		 for(i=0;i<n;i++)
		 {
			 a[i]=cin.nextInt();
			 if(a[i]>Max)
			 {
				 Max=a[i];
				 pos2=pos1;
				 pos1=i;
			 }
			 
		 }
	
		 BigInteger p=new BigInteger(Max+"");
		 BigInteger q;
		if(pos2==-1)
		{
			q=new BigInteger(Max-a[1]+"");
			
		}
		else		
		{
			q=new BigInteger(Max-a[pos2]+"");
		}
		for(i=0;i<n;i++)
		if(a[i]!=Max)
		{
			p=lcm(p,new BigInteger(a[i]+""));
		    q=gcd(q,new BigInteger(Max-a[i]+""));	
		}
		q=q.multiply(new BigInteger("2")); 
		BigInteger t=gcd(p,q) ;
		p=p.divide(t);
		q=q.divide(t);
		System.out.println(p+" "+q); 
	}
	
	static BigInteger gcd(BigInteger a,BigInteger b)
	{
		if(b.equals(BigInteger.ZERO))
		{
			return a;
		}
		else
		return gcd(b,a.mod(b));
	
	}
    static BigInteger lcm(BigInteger a,BigInteger b)
    {
    	
    	return a.divide(a.gcd(b)).multiply(b);
    	
    }
	

}

 
 
 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值