#P9652. 『GROI-R2』 紫水晶

    ID: 10027 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>数学洛谷原创Special JudgeO2优化构造洛谷月赛

『GROI-R2』 紫水晶

Problem Description

Alice has never forgotten that she once existed in the world of playing cards.

So magic made some cards appear in her hand. Magic also made some cards appear in Taniel’s hand, and on each card there was a positive integer—even though they are now in the Glass Kingdom.

The cards quickly vanished, and they were ready to set off. Alice only remembered the sum of the greatest common divisors of each pair of adjacent cards, and Taniel only remembered the sum of the least common multiples of each pair of adjacent cards.

You are still in this palace, and you want to recreate the cards from that time.

Formal statement

You are given qq queries. Each query is one of the following two types:

  • 1 n x means you need to output a positive integer sequence {an}\{a_n\} of length nn, such that i=1n1gcd(ai,ai+1)=x\sum\limits_{i=1}^{n-1} \gcd(a_i,a_{i+1})=x.

  • 2 n x means you need to output a positive integer sequence {an}\{a_n\} of length nn, such that $\sum\limits_{i=1}^{n-1} \operatorname{lcm}(a_i,a_{i+1})=x$.

Also, for any output, each aia_i must not exceed the storage range of int in C++.

Here, gcd\gcd and lcm\operatorname{lcm} are the greatest common divisor and least common multiple. If there are multiple solutions, you may output any one. If there is no solution, output -1.

Input Format

The first line contains a positive integer qq, the number of queries.

Then follow qq lines. Each line contains three positive integers op,n,xop,n,x.

  • When op=1op=1, it means Alice has nn cards and the sum she remembered is xx. You need to restore her cards.

  • When op=2op=2, it means Taniel has nn cards and the sum he remembered is xx. You need to restore his cards.

Output Format

Output qq lines. On each line, output an integer sequence for the card sequence you construct for that query. Adjacent numbers in the sequence should be separated by a single space.

If there are multiple solutions, you may output any one. If there is no solution, output -1.

5
1 5 4
2 3 8
1 5 10
2 6 34
1 3 1
1 1 1 1 1
2 2 3
1 1 1 7 7
1 1 4 5 1 4
-1

Hint

Constraints

This problem uses bundled testdata.

Subtask\text{Subtask} n\sum n\le xx\le Special property Score
11 55 1010 1010
22 5050 200200 2020
33 5×1055\times 10^5 23112^{31}-1 A\text{A} 1515
44 B\text{B}
55 4040

Special property A\text{A}: it is guaranteed that for every query, op=1op=1.

Special property B\text{B}: it is guaranteed that for every query, op=2op=2.

For 100%100\% of the data, 2n5×1052\le n\le 5\times 10^5, 2n5×1052\le \sum n\le 5\times 10^5, 1x23111\le x \le 2^{31}-1, and op{1,2}op\in\{1,2\}.

Translated by ChatGPT 5