POJ 3101 Astronomy (score of least common multiple)

Source: Internet
Author: User
Tags greatest common divisor

Http://poj.org/problem?

Id=3101


Approximate test instructions: The period of an object in a straight line that is not exactly the same as n a period of motion.


This question I read the problem-solving report written, did not expect to choose to use the object, using the physical angular velocity or something.


Since the cycles of n celestial bodies are known, their angular velocities are VI = 2*pi/ti, and if the No. 0 celestial body is chosen as the reference, then the relative velocity of the remaining celestial bodies is VI ' =

2*pi* (T0-ti)/(T0*ti) (the same celestial body as the cycle T). Ti = (T0*ti)/((T0-ti)) is 180 degrees different from the angle of the No. 0 celestial body.

Then the least common multiple of all ti is the answer.


Finally to the point. Ti as fractions, their least common multiple is defined as: the number of least common multiple/total denominator greatest common divisor of all molecules.

Because N is too large, it needs to be processed in large numbers.

And all kinds of Baidu Java. Finally a. Two o ' Night, Wash and sleep.


Import java.math.*;import java.util.*;import java.io.*;p ublic class Main {public static int [] t = new int [main];p ublic s tatic int [] TT = new int [];p ublic static BigInteger [] FZ = new BigInteger [];p ublic static BigInteger [] FM = n EW BigInteger [];p ublic static int gcd (int a, int b) {if (b = = 0) return A;return gcd (b,a%b);} public static void Main (string[] args) {int n,m; Scanner cin = new Scanner (system.in), n = Cin.nextint (), for (int i = 0; i < n; i++) T[i] = Cin.nextint (); Arrays.sort (T,0,n); How to sort an array in Java m = 0;tt[m++] = t[0];for (int i = 1; i < n; i++) {//put cycle the same indent if (t[i]! = T[i-1]) {tt[m++] = T[i];}} for (int i = 1; i < m; i++) {int a = tt[i] * tt[0];int B = (Tt[i]-tt[0]); int g = GCD (A, b); Fz[i] = biginteger.valueof ( a/g); Fm[i] = biginteger.valueof (b/g);} BigInteger T1 = fz[1],t2 = fm[1];for (int i = 2; i < m; i++) {BigInteger AA = t1.multiply (Fz[i]); BigInteger GG = T1.GCD (fz[i]) T1 = aa.divide (gg); t2 = T2.GCD (Fm[i]);} SYSTEM.OUT.PRINTLN (T1 + "" + t2);}}




POJ 3101 Astronomy (score of least common multiple)

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.