GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday, 7 October 2022

[Solution] Ela and Prime GCD Codeforces Solution


F. Ela and Prime GCD
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given an integer 

c. Suppose that c has n divisors. You have to find a sequence with n1 integers [a1,a2,...an1], which satisfies the following conditions:

  • Each element is strictly greater than 1.
  • Each element is a divisor of c.
  • All elements are distinct.
  • For all 1i<n1gcd(ai,ai+1) is a prime number.

In this problem, because c can be too big, the result of prime factorization of c is given instead. Note that gcd(x,y) denotes the greatest common divisor (GCD) of integers x and y and a prime number is a positive integer which has exactly 2 divisors.

Input

The first line contains one integer t (1t104) - the number of test cases.

The first line of each test case contains one integer m (1m16) - the number of prime factor of c.

The second line of each test case contains m integers b1,b2,,bm (1bi<220) — exponents of corresponding prime factors of c, so that c=p1b1p2b2pmbm and n=(b1+1)(b2+1)(bm+1) hold. pi is the i-th smallest prime number.

Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

It is guaranteed that the sum of nm over all test cases does not exceed 220.

Output

Print the answer for each test case, one per line. If there is no sequence for the given c, print 1.

Otherwise, print n1 lines. In i-th line, print m space-separated integers. The j-th integer of i-th line is equal to the exponent of j-th prime number from ai.

If there are multiple answers, print any of them.


No comments:

Post a Comment