CF1737F.Ela and Prime GCD

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After a long, tough, but fruitful day at DTL, Ela goes home happily. She entertains herself by solving Competitive Programming problems. She prefers short statements, because she already read too many long papers and documentation at work. The problem of the day reads:You are given an integer cc . Suppose that cc has nn divisors. You have to find a sequence with n1n - 1 integers [a1,a2,...an1][a_1, a_2, ... a_{n - 1}] , which satisfies the following conditions:

  • Each element is strictly greater than 11 .
  • Each element is a divisor of cc .
  • All elements are distinct.
  • For all 1i<n11 \le i < n - 1 , gcd(ai,ai+1)\gcd(a_i, a_{i + 1}) is a prime number.

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

输入格式

The first line contains one integer tt ( 1t1041 \le t \le 10^4 ) - the number of test cases.

The first line of each test case contains one integer mm ( 1m161 \le m \le 16 ) - the number of prime factor of cc .

The second line of each test case contains mm integers b1,b2,,bmb_1, b_2, \ldots, b_m ( 1bi<2201 \le b_i < 2^{20} ) — exponents of corresponding prime factors of cc , so that c=p1b1p2b2pmbmc = p_1^{b_1} \cdot p_2^{b_2} \cdot \ldots \cdot p_m^{b_m} and n=(b1+1)(b2+1)(bm+1)n = (b_1 + 1)(b_2 + 1) \ldots (b_m + 1) hold. pip_i is the ii -th smallest prime number.

It is guaranteed that the sum of nmn \cdot m over all test cases does not exceed 2202^{20} .

输出格式

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

Otherwise, print n1n - 1 lines. In ii -th line, print mm space-separated integers. The jj -th integer of ii -th line is equal to the exponent of jj -th prime number from aia_i .

If there are multiple answers, print any of them.

输入输出样例

  • 输入#1

    5
    2
    1 1
    1
    1
    3
    1 1 1
    1
    4
    2
    2 1

    输出#1

    0 1 
    1 1 
    1 0 
    1 
    0 1 1 
    0 0 1 
    1 0 1 
    1 1 0 
    0 1 0 
    1 1 1 
    1 0 0 
    -1
    2 0 
    1 1 
    0 1 
    2 1 
    1 0

说明/提示

In each test case, the values of cc are 66 , 22 , 3030 , 1616 , and 1212 in that order.

In the first test case, 11 , 22 , 33 , 66 are divisors of 66 . Here, sequences [2,6,3][2, 6, 3] and [3,6,2][3, 6, 2] can be answer. Permutation [3,2,6][3, 2, 6] is invalid because gcd(a1,a2)=1\gcd(a_1, a_2) = 1 is not a prime number.

In the forth test case, 11 , 22 , 44 , 88 , 1616 are divisors of 1616 . Among the permutation of sequence [2,4,8,16][2, 4, 8, 16] , no valid answer exist.

首页