CF1905E.One-X
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 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 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=⌊2l+r⌋ . Then we call build(2v,l,m) and build(2v+1,m+1,r) .
So, the whole tree is built by calling build(1,1,n) .
Now Ibti will construct a segment tree for an array with n elements. He wants to find the sum of lca†(S) , where S is a non-empty subset of leaves. Notice that there are exactly 2n−1 possible subsets. Since this sum can be very large, output it modulo 998244353 .
†lca(S) is the number of the least common ancestor for the nodes that are in S .
输入格式
Each test consists of multiple test cases. The first line contains a single integer t ( 1≤t≤103 ) — 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≤n≤1018 ) — the length of the array for which the segment tree is built.
输出格式
For each test case, output a single integer — the required sum modulo 998244353 .
输入输出样例
输入#1
5 2 3 4 5 53278
输出#1
6 17 36 69 593324855
说明/提示
In the first test case:
Let's look at all subsets of leaves.
- lca({2})=2 ;
- lca({3})=3 ;
- 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.
- lca({4})=4 ;
- lca({5})=5 ;
- lca({3})=3 ;
- lca({4,5})=2 ;
- lca({4,3})=1 ;
- lca({5,3})=1 ;
- lca({4,5,3})=1 ;
Thus, the answer is 4+5+3+2+1+1+1=17 .