POJ 3101 Astronomy (large number +LCM)

Source: Internet
Author: User

Astronomy
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 5167 Accepted: 1127

Description

There is n planets in the planetary system of Star X. They orbit star X in circular orbits located in the same plane. Their tangent velocities is constant. Directions of orbiting of all planets is the same.

Sometimes the event happens in this planetary system which is called Planet Parade. It was the moment when all planets and star X were located on the same straight line.

Your task is to find the length of the time interval between a 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 is the same.

Output

Output the answer as a common irreducible fraction, separate numerator and denominator by a space.

Sample Input

36 2 3

Sample Output

3 1

some planets revolve around the star, all the planets from the total line, to the next total collinear time. (the topic gives the cycle of each planet)
planets orbit around a star in two ways: on the same side of the star, or on different sides of the star (that is, in different directions) .
definitely related to GCD and LCM. I've lost many times in WA. the red part below is the problem-solving idea, others can not see-*-
① See the topic, direct to the whole planetary cycle of the least common multiple LCM, consider the two cases of collinear, if lcm%2==0, the answer is (lcm/2,1), otherwise the answer is (lcm,2). WA dropped, missed the other situation, think simple.
② then the LCM and the GCD for all cycles, and the same consideration of the collinear there are 2 cases, then gcd*=2, then the answer is numerator (LCM,GCD). Again wa off.
③wa two times I will not deceive myself, this question is not so simple, or to honestly push formula it. for two planets, the cycle is a A, a, a, set after the time t two can be collinear again, then the formula: t* (2*pi/a)-t* (2*pi/b) =m*pi, conversion can be:t= (a*b/(a)) *m, easy to know m take 1 o'clock t minimum, all t=a*b/(A-B), and then draw all such t1,t2,..     TK, ask the least common multiple of these t is the answer (note t to always keep the score, do not directly divide into integers), this program submitted, and WA ... The reason is that there are two planetary cycles that are the same situation, namely a-b=0.
④ Since there is an equal period, then for the equal period only need to deal with a line, then you have to go heavy , good, go heavy, commit, WA .... ⑤ Overflow, first in addition to multiply, expect not to overflow, submit, WA .....
in the algorithm is correct, the situation is also comprehensive situation, but also WA, that is the problem of data, look at the data size, ask least common multiple fool all know 64 also overflow, must large number of, in fact, I have never used the large number of Java, so the problem of large numbers are prohibitive, but this problem I wa to now , how willingly let it go, use Java to do once, this is my first time with Java code.
The big number + the score lcm+ to go heavy, this question is a.
Note that you can make a special sentence for as long as two different periods.
import Java.math.biginteger;import Java.util.scanner;public class Main {final static int maxn=1010;public static int[] A = new INT[MAXN];p ublic static int[] B = new INT[MAXN];p ublic static int[] Vis = new in T[10*MAXN];p ublic 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);d 2=biginteger.valueof (T2); for (i=1;i<k-1;i++) {d3=biginteger.valueof (a[i]*a[i+1]);d 4=biginteger.valueof (Math.Abs (a[i]-a[i+1)); v1=d1.multiply (D4); v2= D2.multiply (D3); x=d1.multiply (D3); Y=V1.GCD (v2); BigInteger temp=x.gcd (y);d 1=x.divide (temp);d 2=y.divide (temp);} System.out.println (d1+ "" +d2);}} 


POJ 3101 Astronomy (large number +LCM)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.