Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 4565 | Accepted: 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
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);
}
}