3101 Astronomy Java大数,分数的最小公倍数

Astronomy
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

Northeastern Europe 2005, Northern Subregion
import java.util.*;
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);
 }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值