MAIN12B - PrimeFactorofLCM

no tags 

Everyone loves Swampy. Swampy the Alligator lives under the city and yearns for a more human like existence. One day Swampy took part in a maths contest to show his supremacy over other his other alligator friends. The task required him to output the prime divisors of the lcm of n numbers a1,a2,..,an. Tired trying the problem, he turned to you for help. He believes that you can help him solve the problem.


First line of the input contains an integer T, the number of test cases. Then T test cases follow. Each test case consists of a single integer n. Next line contains n integers(space separated), a1,a2,..,an.


For each test case, print Case #X: M where M is the number of prime divisors of lcm(a1,a2,..,an) and then M lines with the prime divisors in non-decreasing order.


1 2 3 4 5 6 7 8

Case #1: 4

Constraints: T <= 100 1 <= N <= 100 1 <= ai <= 10^12

Added by:Nikunj Jain
Time limit:1.193s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: SCM chicken
Resource:Vaibhav Mittal

hide comments
black MaMbA: 2014-10-17 21:48:55

is there a space after Case i: and then the no of prime factors

||N0VICE||: 2014-07-01 20:48:51

AC after lots of WAs :)

Akb: 2013-03-29 04:16:29

i chose this one to be my 150th...teaches some good mathematical concepts...!! :)

(^_^): 2013-03-16 08:05:51

200th to solve this problem.
Easy one.

Aditya Pande: 2013-01-05 07:10:31

got AC without precomputing primes using or sieve or something.....

Paul Draper: 2012-11-20 07:28:00

The time limit is appropriate. It prohibits a naive solution, and accepts the solutions of non-C/C++ languages.

Nic Roets: 2012-10-09 20:36:19

I use O(sqrt(a)) algorithm and got AC with 2s. I am however convinced that the tests in the judge are not very hard:

When I run it on the test case below, it took 65s on my Pentium M 1.7GHz.

999999999989 ...
(Some more prime numbers exceeding 10^11)

Bharath Reddy: 2012-07-16 12:52:39

TLE using naive algo...
Worst case running for 34 sec on my comp

Last edit: 2012-07-16 12:53:10
PubLic_AvenGeR: 2012-06-29 08:47:24

Time Limit is too relaxed,Should be around 4-5 sec.Nice question anyways.

15972125841321: 2012-06-03 12:09:14

can someone plz tell me where i m getting wa... my sub id 7083656