Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5167 | Accepted: 1127 |
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
import java.math.BigInteger; import java.util.Scanner; public class Main { final static int maxn=1010; public static int[] a = new int[maxn]; public static int[] b = new int[maxn]; public static int[] vis = new int[10*maxn]; public static long gcd(long a,long b){ return b==0?a:gcd(b,a%b); } public static void main(String[] args){ Scanner in = new Scanner(System.in); int i,n,k; n=in.nextInt();k=0; for(i=0;i<vis.length;i++) vis[i]=0; for(i=0;i<n;i++){ int t=in.nextInt(); if(vis[t]==0){ a[k++]=t; vis[t]=1; } } long t1,t2,g; t1=a[0]*a[1]; t2=Math.abs(a[0]-a[1])*2; if(k==2){ g=gcd(t1,t2); System.out.println(t1/g+" "+t2/g); } else { BigInteger d1,d2,d3,d4,x,y,v1,v2; d1=BigInteger.valueOf(t1); d2=BigInteger.valueOf(t2); for(i=1;i<k-1;i++){ d3=BigInteger.valueOf(a[i]*a[i+1]); d4=BigInteger.valueOf(Math.abs(a[i]-a[i+1])*2); v1=d1.multiply(d4); v2=d2.multiply(d3); x=d1.multiply(d3); y=v1.gcd(v2); BigInteger temp=x.gcd(y); d1=x.divide(temp); d2=y.divide(temp); } System.out.println(d1+" "+d2); } } }
原文地址:http://blog.csdn.net/u013068502/article/details/45576531