33OJ
登录 注册

#P17824. [COCI 2026/2027 #1] 有轨电车 / Tramvaj

    ID: 20478 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>图论数论Special Judge图论建模群论构造COCI(克罗地亚)2026Ad-hoc

[COCI 2026/2027 #1] 有轨电车 / Tramvaj

Problem Description

The tram network in a certain city can be pictured as nn tram stations evenly spaced around a circle. The tram stations are labeled with the positive integers from 11 to nn in clockwise order. There is exactly one track between every two stations, and trams always travel clockwise.

A ride of length ll (1≤l≤n−11 \le l \le n-1) takes you from your current station to the station ll stops further along in the clockwise direction.

The Tram Administration sells a separate ticket for each ride length. As part of a promotional campaign, they decided to color each type of ticket and offer a free monthly pass to any person who:

  • returns, through a sequence of rides, to the station they started from, and
  • uses tickets of pairwise distinct colors on that trip.

The bosses at the Administration liked the idea of coloring tickets as a promotional strategy, but not the idea of someone riding their trams for free, so they will agree to the coloring only if no person can win the free monthly pass.

Of course, all tickets could be the same color, but then it would be immediately obvious to the public that winning the free monthly pass is impossible. Not bothered by concerns about false advertising, the bosses ask you for a coloring that uses as many colors as possible!

Input Format

The first line contains a positive integer tt (1≤t≤10001 \le t \le 1000), the number of scenarios.

Each of the following tt lines contains a positive integer nn (2≤n≤2⋅1052 \le n \le 2\cdot 10^5), the number of tram stations in the network.

The sum of nn over all scenarios will not exceed 2⋅1052\cdot 10^5.

Output Format

For each of the tt scenarios, in order, output two lines.

In the first line, output a positive integer kk, the number of colors used to color the tickets.

In the second line, output n−1n-1 numbers c1,…,cn−1c_1,\ldots,c_{n-1} separated by spaces, where cic_i is the color of the ride of length ii. Each color must be a positive integer from the set {1,2,…,k}\{1,2,\ldots,k\}, and every number in that set must appear at least once.

1
3
1
1 1
2
4
5
2
2 1 2
2
1 2 2 1
1
6
2
2 1 2 1 2

Hint

Scoring

In each scenario, let kk be the number of colors output by your solution, and let koptk_{\mathrm{opt}} be the largest possible number of colors. If the coloring output in any scenario does not satisfy the conditions of the problem, the solution scores 0 points on that test case.

Otherwise, for each scenario we compute the ratio

$$r=\begin{cases} 1, & \text{if } k_{\mathrm{opt}}=1 \text{ and } k=1,\\ \dfrac{k-1}{k_{\mathrm{opt}}-1}, & \text{if } k_{\mathrm{opt}}>1. \end{cases}$$

The fraction of points earned on a test case is the minimum ratio rr over all scenarios in that test case. The number of points earned on a subtask is the subtask's point value multiplied by the minimum such fraction over all test cases in that subtask.

Subtask Points Constraints
1 20 n≤12n \le 12.
2 10 nn is a prime number.
3 15 nn is a power of 22.
4 65 No additional constraints.