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
import java.io.*;
import java.math.*;
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));
}
}
行星游行问题解析

本文探讨了给定多个行星围绕恒星X运行周期的情况下,如何计算行星与恒星位于同一直线上的最短时间间隔。介绍了通过求取最小公倍数来解决这一问题的方法,并提供了一段使用Java实现的具体代码。
1098

被折叠的 条评论
为什么被折叠?



