CF1737F.Ela and Prime GCD

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

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 \lt 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.

在 DTL 经历了漫长、艰辛但富有成果的一天后,Ela 心情愉快地回到了家。她通过解决竞赛编程题目来娱乐自己。她偏爱简短的题面,因为在工作中她已经阅读了太多冗长的论文和文档。当天的题目如下:

给定一个整数 cc。假设 ccnn 个正因数。你需要构造一个包含 n1n - 1 个整数的序列 [a1,a2,,an1][a_1, a_2, \dots, a_{n - 1}],满足以下条件:

  • 每个元素严格大于 11
  • 每个元素均为 cc 的正因数;
  • 所有元素互不相同;
  • 对所有 1i<n11 \le i < n - 1gcd(ai,ai+1)\gcd(a_i, a_{i + 1}) 是一个质数。

本题中,由于 cc 可能过大,因此直接给出其质因数分解结果。注意:gcd(x,y)\gcd(x, y) 表示整数 xxyy 的最大公约数(GCD),而质数是指恰好有 22 个正因数的正整数。

输入格式

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 \lt 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}.

第一行包含一个整数 tt1t1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 mm1m161 \le m \le 16)——cc 的质因数个数。

每个测试用例的第二行包含 mm 个整数 b1,b2,,bmb_1, b_2, \ldots, b_m1bi<2201 \le b_i \lt 2^{20})——分别对应 cc 的各质因数的指数,使得 c=p1b1p2b2pmbmc = p_1^{b_1} \cdot p_2^{b_2} \cdot \ldots \cdot p_m^{b_m}n=(b1+1)(b2+1)(bm+1)n = (b_1 + 1)(b_2 + 1) \ldots (b_m + 1) 成立。其中 pip_i 表示第 ii 个最小的质数。

保证所有测试用例中 nmn \cdot m 的总和不超过 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.

对每个测试用例,输出一行答案。若不存在满足给定 cc 的序列,则输出 1-1

否则,输出 n1n - 1 行。在第 ii 行中,输出 mm 个以空格分隔的整数;其中第 jj 个整数等于 aia_i 中第 jj 个质数的指数。

若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#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.

每个测试用例中,cc 的值依次为 6622303016161212

在第一个测试用例中,1122336666 的约数。此时,序列 [2,6,3][2, 6, 3][3,6,2][3, 6, 2] 均可作为答案。排列 [3,2,6][3, 2, 6] 无效,因为 gcd(a1,a2)=1\gcd(a_1, a_2) = 1 不是质数。

在第四个测试用例中,1122448816161616 的约数。在序列 [2,4,8,16][2, 4, 8, 16] 的所有排列中,不存在合法答案。

输入解题思路,AI测评打分。不知道怎么写?

首页