【POJ3101】Astronomy——分子的最小公倍数

来源:互联网 发布:形容闪亮的网络词语 编辑:程序博客网 时间:2024/04/28 09:57

Astronomy

Time Limit: 2000MS Memory Limit: 65536K

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
3101_1.gif
Source

Northeastern Europe 2005, Northern Subregion

题意:已知每一个行星的周期,求他们共线的最短的时间。

vi=2πTi,00vi=2πTiT0TiTo,Ti=πvi=TiT02(TiT0)T1,T2,T3,Tn1LCM(a,b)=a×bGCD(a,b),LCM(ab,cd)=LCM(a,c)GCD(b,d)mnab,cdmn×ba=N,mn×dc=Nma,cnb,dmnm=LCM(a,c),n=GCD(b,d)Java

import java.math.*;import java.util.*;public class Main {    public static void main(String[ ]  args)    {        Scanner cin = new Scanner(System.in);        int n  ,cnt;        int [ ] t  =new  int[1100];        int [ ]s = new int [1100];        BigInteger a,b,g,mo = null,de = null;        while(cin.hasNext())        {            cnt = 1;            n = cin.nextInt();            for(int i = 0;i<n;i++) t[i] = cin.nextInt();            Arrays.sort(t,0,n);            s[0]  =t[0];            for(int i = 1;i<n;i++)            {                               if(t[i]!=t[i-1])                {                    s[cnt++] = t[i];                }            }            for(int i = 1;i<cnt;i++)            {                a = BigInteger.valueOf(s[i]*s[0]);                b = BigInteger.valueOf((s[i]-s[0])*2);                g =  a.gcd(b);                if(i == 1)                {                    mo = a.divide(g);                    de = b.divide(g);                 }                else                {                    a  = a.divide(g);                    b = b.divide(g);                    mo = mo.multiply(a).divide(mo.gcd(a));                    de = de.gcd(b);                }            }            System.out.println(mo+" "+de);        }        cin.close();    }}
0 0
原创粉丝点击