#P10157. [LSOT-2] Tree and Xor

    ID: 10685 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学贪心二分位运算Ad-hoc分类讨论

[LSOT-2] Tree and Xor

Problem Description

Given nn, you need to construct a rooted tree with nn nodes, rooted at 11, such that i=1ndegree(i)=0\bigoplus\limits_{i=1}^ndegree(i)=0 and the sequence fa2fanfa_2 \sim fa_n is lexicographically smallest. Here, \oplus denotes the XOR operation.

Here, degree(i)degree(i) denotes the number of nodes connected to node ii, faifa_i denotes the parent of node ii, and fai<ifa_i < i.

You need to output i=2ni×fai\sum\limits_{i=2}^ni \times fa_i. If there is no solution, output 1-1.

Input Format

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

In the next TT lines, each line contains a positive integer nn, indicating one query.

Output Format

Output TT lines in total. Each line contains one integer, the answer modulo 998244353998244353.

2
2
3
2
-1

Hint

"This problem uses bundled tests."

  • Subtask 1(5 pts):n7\texttt{Subtask 1(5 pts):}n \leq 7.
  • Subtask 2(10 pts):n20\texttt{Subtask 2(10 pts):} n \leq 20.
  • Subtask 3(20 pts):n2000\texttt{Subtask 3(20 pts):}\sum n \leq 2000.
  • Subtask 4(15 pts):n=2k1\texttt{Subtask 4(15 pts):}n = 2^k-1, where kk is a natural number.
  • Subtask 5(50 pts):\texttt{Subtask 5(50 pts):}No special constraints.

For all testdata, 1T1061\le T\le 10^6, 2n1092 \leq n \leq 10^{9}.

Translated by ChatGPT 5