# Swun 1428-planetary sphere

Source: Internet
Author: User

 Planetary livemix Time limit (Common/Java): 8000 MS/16000 MS running memory limit: 65536 KbyteTotal submission: 57 tested: 5 Description It is usually seen with the naked eye. When a planet is almost in a straight line, it is called a "planetary ball ".     The N-star Concatenation refers to the fact that N planets in the solar system are in the same straight line at the same time.   It is known that all the N planets are centered around the sun for a uniform circular motion, and the cycle of the I-th planet is Ti Day (that is, the time of a circle around the circumference ).   Now, snow_storm wants to know the minimum interval between the appearance of N-star beads? Input The first positive integer T (t <= 300) indicates the number of test groups. For each group of test data, there is a positive integer N (2 <=n <=10000), Indicating that there are n planets In the next row, there are n positive integers Ti (1 <= Ti <= 10000). The number of I represents the revolution cycle of the I planet. Output For each group of test data, the minimum interval is output. Sample Input 335 6 742 4 6 845 6 30 60 Sample output Case 1: 210Case 2: 24Case 3: 60 Question Source Yb

Http: // 218.194.91.48/acmhome/problemdetail. do? & Method = showdetail & id = 1428

When I see this question, it is easy to know that it is to find the minimum public multiple of all numbers, but the product is very large.

So I was excited to write a Java big integer ~~~

N has not been written for a long time.

After knocking, submit, and RE in group 5th.

I checked N for a long time. I suspect that the data contains 0, except 0... Q: Why ~~

During the retrial, the N range was changed from 1000 to 10000...

(When the data range is 1000, my javaCodeIt should be Ac-enabled ~~~ Region ~ According to the author, the question data is out of water and the range is wrong ~~ Various Regions)

Taking the test method (Train of Thought) without luck, the author gave me the best TLE of my code ~~~ (The write method is incorrect ~)

Think about it, use C ++ instead (better than Java ...)...

The idea is very simple. First, enumerate all prime numbers within 100 (10000 after the start of 100 is 10000, so the sum of less than 100 certainly has a factor of less. Does not include the number of times, which is the prime number )...

Then record how many times each prime number appears in all numbers...

If the expression is repeated, the common factor is removed )...

Then we use the multiplication of large numbers to store the results. (Of course, we have also done it again. After that, we decided that when the number of new multiply entries is 1, do not multiply the number )...

Is it an AC? Although the data is really brutal...

Later, I changed the Java code ~~~~

========================================================== ========================================================== ======================================

C ++ code:

`# Include <cstdio> # include <iostream> # include <cstring> # include <algorithm> using namespace STD; struct bigint {int Len, num ; bigint () {} bigint (int x) {Len = 1; num  = x;} void MUL (int x) {int I; for (I = 0; I <Len; I ++) num [I] * = x; for (I = 0; I <len-1; I ++) if (Num [I]> = 100000) {num [I + 1] + = num [I]/100000; num [I] % = 100000;} If (Num [len-1]> = 100000) {num [Len] = num [len-1]/100000; num [len-1] % = 100000; Len ++ ;}} void print () {printf ("% d ", num [-- Len]); While (Len --) printf ("% 05d", num [Len]); puts ("") ;}}; int prime ; int rec , CNT; int gcd (int x) {int I, J, K, num, res, M; Res = 1; for (I = 0; I <CNT & x> = rec [I]; I ++) {num = 0; while (X % rec [I] = 0) {num ++; x/= rec [I];} If (Num> 0) {If (Num <= prime [Rec [I]) continue; else {M = num-prime [Rec [I]; prime [Rec [I] = num; while (M --) RES * = rec [I] ;}} if (X & prime [x] = 0) {res * = x; prime [x] = 1;} return res;} int init _() {memset (Prime, 0, sizeof (PRIME); int I, j; CNT = 0; for (I = 2; I <= 100; I ++) {If (prime [I]) continue; For (j = I + I; j <= 100; j + = I) prime [J] = 1; REC [CNT ++] = I ;}} int init_1 () {memset (Prime, 0, sizeof (PRIME);} int A ; int CMP (int x, int y) {return x> Y;} int main () {int T, TT, N, I, TMP; bigint res; scanf ("% d", & T); init _ (); For (TT = 1; TT <= T; TT ++) {init_1 (); scanf ("% d", & N); for (I = 0; I <n; I ++) scanf ("% d", & A [I]); sort (A, A + N, CMP); Res = bigint (A ); gcd (A ); for (I = 1; I <N; I ++) {TMP = gcd (A [I]); If (TMP = 1) continue; Res. mul (TMP);} printf ("case % d:", TT); Res. print ();} return 0 ;}`

========================================================== ========================================================== ======================================

Java code:

`Import Java. util. *; import Java. math. *; public class main {static int [] Prime = new int ; static int [] rec = new int ; static int CNT; static int gcd (int x) {int I, J, K, num, res, M; Res = 1; for (I = 0; I <CNT & x> = rec [I]; I ++) {num = 0; while (X % rec [I]) = 0) {num ++; X/= rec [I];} If (Num> 0) {If (Num <= prime [Rec [I]) continue; else {M = num-prime [Rec [I]; prime [Rec [I] = num; while (M> 0) {M --; res * = rec [I] ;}}} if (x> 1 & prime [x] = 0) {res * = X; prime [x] = 1;} return res;} static void init _ () {int I, j; for (I = 0; I <= 100; I ++) prime [I] = 0; CNT = 0; for (I = 2; I <= 100; I ++) {If (prime [I] = 1) continue; for (j = I + I; j <= 100; j + = I) prime [J] = 1; REC [CNT ++] = I ;}} public static void main (string ARGs []) {program CIN = new program (system. in); int T, TT, N, J, I, TMP, M; biginteger res, now; t = cin. nextint (); init _ (); For (TT = 1; TT <= T; TT ++) {for (j = 0; j <= 10000; j ++) prime [J] = 0; n = cin. nextint (); TMP = cin. nextint (); Res = biginteger. valueof (TMP); gcd (TMP); for (I = 1; I <n; I ++) {TMP = cin. nextint (); M = gcd (TMP); If (M = 1) continue; Res = res. multiply (biginteger. valueof (m);} system. out. println ("case" + tt + ":" + Res );}}}`

Related Keywords:

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.