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 c. Suppose that c has n divisors. You have to find a sequence with n−1 integers [a1,a2,...an−1], 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 1≤i<n−1, gcd(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.

在 DTL 经历了漫长、艰辛但富有成果的一天后,Ela 心情愉快地回到了家。她通过解决竞赛编程题目来娱乐自己。她偏爱简短的题面,因为在工作中她已经阅读了太多冗长的论文和文档。当天的题目如下:
给定一个整数 c。假设 c 有 n 个正因数。你需要构造一个包含 n−1 个整数的序列 [a1,a2,…,an−1],满足以下条件:
- 每个元素严格大于 1;
- 每个元素均为 c 的正因数;
- 所有元素互不相同;
- 对所有 1≤i<n−1,gcd(ai,ai+1) 是一个质数。
本题中,由于 c 可能过大,因此直接给出其质因数分解结果。注意:gcd(x,y) 表示整数 x 与 y 的最大公约数(GCD),而质数是指恰好有 2 个正因数的正整数。
输入格式
The first line contains one integer t (1≤t≤104) - the number of test cases.
The first line of each test case contains one integer m (1≤m≤16) - the number of prime factor of c.
The second line of each test case contains m integers b1,b2,…,bm (1≤bi<220) — exponents of corresponding prime factors of c, so that c=p1b1⋅p2b2⋅…⋅pmbm and n=(b1+1)(b2+1)…(bm+1) hold. pi is the i-th smallest prime number.
It is guaranteed that the sum of n⋅m over all test cases does not exceed 220.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含一个整数 m(1≤m≤16)——c 的质因数个数。
每个测试用例的第二行包含 m 个整数 b1,b2,…,bm(1≤bi<220)——分别对应 c 的各质因数的指数,使得 c=p1b1⋅p2b2⋅…⋅pmbm 且 n=(b1+1)(b2+1)…(bm+1) 成立。其中 pi 表示第 i 个最小的质数。
保证所有测试用例中 n⋅m 的总和不超过 220。
输出格式
Print the answer for each test case, one per line. If there is no sequence for the given c, print −1.
Otherwise, print n−1 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.
对每个测试用例,输出一行答案。若不存在满足给定 c 的序列,则输出 −1。
否则,输出 n−1 行。在第 i 行中,输出 m 个以空格分隔的整数;其中第 j 个整数等于 ai 中第 j 个质数的指数。
若存在多个合法答案,输出任意一个即可。
输入输出样例
输入#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 c are 6, 2, 30, 16, and 12 in that order.
In the first test case, 1, 2, 3, 6 are divisors of 6. Here, sequences [2,6,3] and [3,6,2] can be answer. Permutation [3,2,6] is invalid because gcd(a1,a2)=1 is not a prime number.
In the forth test case, 1, 2, 4, 8, 16 are divisors of 16. Among the permutation of sequence [2,4,8,16], no valid answer exist.
每个测试用例中,c 的值依次为 6、2、30、16 和 12。
在第一个测试用例中,1、2、3、6 是 6 的约数。此时,序列 [2,6,3] 和 [3,6,2] 均可作为答案。排列 [3,2,6] 无效,因为 gcd(a1,a2)=1 不是质数。
在第四个测试用例中,1、2、4、8、16 是 16 的约数。在序列 [2,4,8,16] 的所有排列中,不存在合法答案。
输入解题思路,AI测评打分。不知道怎么写?