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
一拿到表示毫无感觉,手贱了下,看了下discuss,豁然开朗!ORZ!!
题意:已知n个点的环绕点X的周期,求出各点转到同一直线上的最短时间
方法:先预处理下,先把周期一样的行星缩成一个,再求出相邻点间相距半圈所需时间 t = t[i]*t[i-1] / ( (t[i] - t[i-1]) * 2 )。然后求出各个半圈时间的最小公倍数为结果
Hint:需大数
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
public static void main(String[] args){
Scanner cin = new Scanner (System.in);
int n;
int[] t = new int[10005];
BigInteger[] tmp = new BigInteger[10005];
BigInteger[] tm = new BigInteger[10005];
n = cin.nextInt();
for(int i=0; i<n; i++)
t[i] = cin.nextInt();
Arrays.sort(t, 0, n);
int cnt = 1;
for(int i=1; i<n; i++)
if(t[i] != t[cnt-1]){
t[cnt++] = t[i];
}
cnt--;
for(int i=0; i<cnt; i++){
tmp[i] = BigInteger.valueOf(t[i]).multiply(BigInteger.valueOf(t[cnt]));
tm[i] = (BigInteger.valueOf(t[cnt]).subtract(BigInteger.valueOf(t[i]))).multiply(BigInteger.valueOf(2));
}
BigInteger temp1 = tmp[0], temp2 = tm[0];
BigInteger ans;
for(int i=1;i<cnt; i++){
temp1 = temp1.multiply(tm[i]);
tmp[i] = tmp[i].multiply(temp2);
ans = temp1.gcd(tmp[i]);
temp1=temp1.multiply(tmp[i]);
temp1=temp1.divide(ans);
temp2=temp2.multiply(tm[i]);
ans=temp1.gcd(temp2);
temp1=temp1.divide(ans);
temp2=temp2.divide(ans);
}
ans = temp1.gcd(temp2);
System.out.println(temp1.divide(ans)+" "+temp2.divide(ans));
}
}