Astronomy
Time Limit: 2000MS Memory Limit: 65536K
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
题意:已知每一个行星的周期,求他们共线的最短的时间。
分析:每一个行星的角速度为vi=2πTi,选择行星0为参考点,则相对于行星0的角速度为v′i=2πTi−T0TiTo,则转动半圈的时间为T′i=πv′i=TiT02(Ti−T0)问题就转化为求T′1,T′2,T′3⋯,T′n−1的最小公倍数最小公倍数:对于整数的最小公倍数为LCM(a,b)=a×bGCD(a,b),那么对于分数呢?结论:LCM(ab,cd)=LCM(a,c)GCD(b,d)证明:假设mn是ab,cd的最小公倍数,那么mn×ba=N,mn×dc=N′显然m是a,c的倍数,n是b,d的约数,由于是最小公倍数,那么自然是m尽量的小,n尽量的大。所以m=LCM(a,c),n=GCD(b,d)。由于数据的结果比较的大,所以用高精度算法或者是Java。
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[ ] args)
{
Scanner cin = new Scanner(System.in);
int n ,cnt;
int [ ] t =new int[1100];
int [ ]s = new int [1100];
BigInteger a,b,g,mo = null,de = null;
while(cin.hasNext())
{
cnt = 1;
n = cin.nextInt();
for(int i = 0;i<n;i++) t[i] = cin.nextInt();
Arrays.sort(t,0,n);
s[0] =t[0];
for(int i = 1;i<n;i++)
{
if(t[i]!=t[i-1])
{
s[cnt++] = t[i];
}
}
for(int i = 1;i<cnt;i++)
{
a = BigInteger.valueOf(s[i]*s[0]);
b = BigInteger.valueOf((s[i]-s[0])*2);
g = a.gcd(b);
if(i == 1)
{
mo = a.divide(g);
de = b.divide(g);
}
else
{
a = a.divide(g);
b = b.divide(g);
mo = mo.multiply(a).divide(mo.gcd(a));
de = de.gcd(b);
}
}
System.out.println(mo+" "+de);
}
cin.close();
}
}