After solving Rectangles, you thought you had finally escaped primary school geometry.
Unfortunately, Rock has prepared another problem for you.
There is an infinite grid of square cells. Initially, every cell is white. The cell in column $x$ and row $y$ is denoted by $(x,y)$, where $x,y\geq0$.
For every positive integer $K$, Rock has one square of side length $K$. The square of side length $K$ always has its bottom-left corner at $(0,0)$, so it covers all cells $(x,y)$ satisfying $0\leq x\lt K, 0\leq y\lt K.$
You may choose any number of these squares, but each square can be chosen at most once.
Whenever you choose a square, every cell covered by it changes colour: a white cell becomes black, while a black cell becomes white.
You are given $T$ queries. For each query $t$, Rock wants exactly $Q_t$ cells to be black after all the chosen squares have been used.
For each query, determine whether this is possible. If it is possible, output any valid set of square side lengths.
Input
The first line contains an integer $T$, the number of queries.
Each of the next $T$ lines contains one integer, $Q_t$, the required number of black cells.
Output
For each query:
- If it is impossible, output
No. -
Otherwise, output
Yeson one line. On the next line, output an integer $M$, the number of squares chosen. On the following line, output $M$ distinct positive integers $K_1,K_2,\ldots,K_M$, representing the side lengths of the chosen squares.
There may be more than one valid answer. You may output any one of them.
The side lengths you output must not exceed $10^{9}$.
Constraints
For all cases:
$1\leq T\leq2\times10^5$
$1\leq Q_t\leq10^{9}$ for all $1\le t\le T$
Subtask 1 (15%): $Q_t$ is a perfect square for all $1\le t\le T$
Subtask 2 (25%): $Q_t+1$ is a perfect square for all $1\le t\le T$
Subtask 3 (35%): $Q_t$ is odd for all $1\le t\le T$
Subtask 4 (25%): No additional constraints
Sample Test Cases
| Input | Output | |
|---|---|---|
| 4 1 2 14 17 |
Yes 1 1 No Yes 4 2 3 4 5 Yes 3 1 3 5 |
|
The examples for $Q=14$ and $Q=17$ each leave the requested number of black cells. No choice of squares leaves exactly two cells black.
|
||
| 3 8 10 20 |
Yes 2 1 3 Yes 4 1 2 3 4 Yes 3 2 3 5 |
|
The chosen side lengths may be listed in any order, but they must be distinct. The three answers shown each leave the requested number of black cells.
|
||
Scoring: Per Subtask
Authored by s19x17
Appeared in 2026 Wah Yan Interschool Olympiad in Informatics 🤯🥷⚡🧠🏆