Codeforces Round 915 (Div. 2)
E
One-X
Codeforces
2400
原题
← DF →
翻译中…

In this sad world full of imperfections, ugly segment trees exist.

翻译中…

A segment tree is a tree where each node represents a segment and has its number. A segment tree for an array of $n$ elements can be built in a recursive manner. Let's say function $\operatorname{build}(v,l,r)$ builds the segment tree rooted in the node with number $v$ and it corresponds to the segment $[l,r]$.

翻译中…

Now let's define $\operatorname{build}(v,l,r)$:

翻译中…
  • If $l=r$, this node $v$ is a leaf so we stop adding more edges
  • Else, we add the edges $(v, 2v)$ and $(v, 2v+1)$. Let $m=\lfloor \frac{l+r}{2} \rfloor$. Then we call $\operatorname{build}(2v,l,m)$ and $\operatorname{build}(2v+1,m+1,r)$.
翻译中…

So, the whole tree is built by calling $\operatorname{build}(1,1,n)$.

翻译中…

Now Ibti will construct a segment tree for an array with $n$ elements. He wants to find the sum of $\operatorname{lca}^\dagger(S)$, where $S$ is a non-empty subset of leaves. Notice that there are exactly $2^n - 1$ possible subsets. Since this sum can be very large, output it modulo $998\,244\,353$.

翻译中…

$^\dagger\operatorname{lca}(S)$ is the number of the least common ancestor for the nodes that are in $S$.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 10^{18}$) — the length of the array for which the segment tree is built.

翻译中…

Output

翻译中…

For each test case, output a single integer — the required sum modulo $998\,244\,353$.

翻译中…

Note

翻译中…

image

翻译中…

In the first test case:

翻译中…

Let's look at all subsets of leaves.

翻译中…
  • $\operatorname{lca}(\{2\})=2$;
  • $\operatorname{lca}(\{3\})=3$;
  • $\operatorname{lca}(\{2,3\})=1$.
翻译中…

Thus, the answer is $2+3+1=6$.

翻译中…

In the second test case:

翻译中…

Let's look at all subsets of leaves.

翻译中…
  • $\operatorname{lca}(\{4\})=4$;
  • $\operatorname{lca}(\{5\})=5$;
  • $\operatorname{lca}(\{3\})=3$;
  • $\operatorname{lca}(\{4,5\})=2$;
  • $\operatorname{lca}(\{4,3\})=1$;
  • $\operatorname{lca}(\{5,3\})=1$;
  • $\operatorname{lca}(\{4,5,3\})=1$;
翻译中…

Thus, the answer is $4+5+3+2+1+1+1=17$.

翻译中…

样例

Input #1
5
2
3
4
5
53278
Output #1
6
17
36
69
593324855
InputCopy OutputCopy
题目信息
题号
1905E
时间限制
3 s
内存限制
512 MB
标签
组合数学
DFS 及类似
动态规划
数学
树

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