Pinely Round 4 (Div. 1 + Div. 2)
D
Prime XOR Coloring
Codeforces
1900
原题
← CE →
翻译中…

You are given an undirected graph with $n$ vertices, numbered from $1$ to $n$. There is an edge between vertices $u$ and $v$ if and only if $u \oplus v$ is a prime number, where $\oplus$ denotes the bitwise XOR operator.

翻译中…

Color all vertices of the graph using the minimum number of colors, such that no two vertices directly connected by an edge have the same color.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of test cases follows.

翻译中…

The only line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of vertices in the graph.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output two lines.

翻译中…

The first line should contain a single integer $k$ ($1 \le k \le n$) — the minimum number of colors required.

翻译中…

The second line should contain $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \le c_i \le k$) — the color of each vertex.

翻译中…

If there are multiple solutions, output any of them.

翻译中…

Note

翻译中…

In the first test case, the minimum number of colors is $1$, because there is only one vertex.

翻译中…

In the second test case, the minimum number of colors is $2$, because there is an edge connecting $1$ and $2$ ($1 \oplus 2 = 3$, which is a prime number).

翻译中…

In the third test case, the minimum number of colors is still $2$, because $2$ and $3$ can be colored the same since there is no edge between $2$ and $3$ ($2 \oplus 3 = 1$, which is not a prime number).

翻译中…

In the fourth test case, it can be shown that the minimum number of colors is $3$.

翻译中…

In the fifth test case, it can be shown that the minimum number of colors is $3$.

翻译中…

In the sixth test case, it can be shown that the minimum number of colors is $4$.

翻译中…

样例

Input #1
6
1
2
3
4
5
6
Output #1
1
1
2
1 2
2
1 2 2
3
1 2 2 3
3
1 2 2 3 3
4
1 2 2 3 3 4
InputCopy OutputCopy
题目信息
题号
1991D
时间限制
2 s
内存限制
256 MB
标签
位运算
构造
图论
贪心
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。