Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 2704 | Accepted: 553 |
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.math.*;
public class Main
{
public static void main(String args[])throws Exception
{
Scanner cin=new Scanner(System.in);
int n = cin.nextInt();
int num[]=new int[n];
int den[]=new int[n];
int per[]=new int[n];
for(int i = 0; i < n; i++)
per[i]=cin.nextInt();
Arrays.sort(per);
int cnt=1;
for(int i = 1; i < n; i++)
if(per[i]!=per[cnt-1])per[cnt++]=per[i];
for(int i = 0; i < cnt-1; i++)
{
num[i]=per[cnt-1]*per[i];
den[i]=2*(per[cnt-1] - per[i]);
int g=gcd(num[i],den[i]);
num[i]/=g;den[i]/=g;//important
//int c = gcd(num[i],den[i]);
//num[i]=num[i]/c;
//den[i]=den[i]/c;
}
BigInteger ansn= new BigInteger(num[0]+"");
BigInteger ansd= new BigInteger(den[0]+"");
for(int i = 1; i < cnt-1; i++)
{
BigInteger tempn = new BigInteger(num[i]+"");
BigInteger tempd = new BigInteger(den[i]+"");
/*ansn=ansn.multiply(tempd);
tempn=tempn.multiply(ansd);
ansn=lcm(ansn,tempn);
ansd=ansd.multiply(tempd);
BigInteger g = ansn.gcd(ansd);
ansn=ansn.divide(g);//ansn = ansn/g;
ansd=ansd.divide(g);//ansd = ansd/g;*/
ansn=lcm(ansn,tempn);
ansd=ansd.gcd(tempd);
}
BigInteger g = ansn.gcd(ansd);
ansn=ansn.divide(g);
ansd=ansd.divide(g);
System.out.println(ansn+" "+ansd);
}
static int gcd(int x,int y)
{
if (x == 0 || y == 0) if(x > y) return x; else return y;
for (int t; (t = x % y) != 0; x = y, y = t);
return y;
}
static BigInteger lcm(BigInteger a,BigInteger b)
{
BigInteger c = a.gcd(b);
return a.multiply(b).divide(c);
}
}