#SP0000246. Tô màu đồ thị XOR nguyên tố (Prime XOR Coloring)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tô màu đồ thị XOR nguyên tố (Prime XOR Coloring)
Prime XOR Coloring
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Consider an undirected graph with vertices numbered . Two distinct vertices and are adjacent if and only if is prime, where denotes bitwise XOR. A prime is an integer greater than with exactly two positive divisors.
Color all vertices so that the endpoints of every edge have different colors, using the minimum possible number of colors. Any optimal coloring is accepted.
Input
The only line contains integer , the number of vertices. Edges are determined by the XOR rule; no edge list is provided.
Output
- On the first line, print the minimum number of colors.
- On the second line, print exactly integers with , where is the color of vertex .
- For every edge , must hold. Any coloring achieving minimum is valid.
Subtasks
- Subtask 1 (20 points): ; vertices numbered from to .
- Subtask 2 (30 points): ; vertices numbered from to .
- Subtask 3 (50 points): ; vertices numbered from to .
Examples
Input
6
Output
4
1 2 3 4 1 2
Explanation
Here , and the output assigns colors . Vertices and share color but is not prime. Likewise, is not prime, so the other repeated color is also legal. All other colors occur only once. The vertices are pairwise adjacent: their six XOR values are , all prime. They therefore require at least four colors. The displayed coloring uses exactly four, so it is optimal.