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,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); } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。