#P7143. [THUPC 2021 初赛] 线段树
[THUPC 2021 初赛] 线段树
Description
The segment tree is Little L’s favorite data structure. It can efficiently solve many practical problems.
Given a positive integer , Little L builds a segment tree whose indices belong to the integer interval :
- Initially, the segment tree has only one node .
- For a node , if , let (where denotes the greatest integer not exceeding ). Little L creates two child nodes for this node: and .
Little L defines a function (), which means using several segment tree nodes to cover the interval without overlap and without omission. is the minimum possible number of segment tree nodes used.
Little L tries to use this segment tree to solve a complex problem, and wants to roughly evaluate the performance of this segment tree.
Specifically, the interval has different sub-intervals. If Little L randomly selects one sub-interval from these sub-intervals with equal probability, denoted as , then Little L believes the expected value of can be used to evaluate the performance of this segment tree.
Little L wants you to help compute the result of multiplied by modulo . You may find that this result must be an integer.
Input Format
The first line contains a positive integer (), indicating the number of test cases.
The next lines follow. In the -th line (), there is a positive integer (), indicating the value of for the -th test case.
Output Format
Output lines. In the -th line (), output one integer representing the answer for the -th test case.
1
3
7
Hint
[Sample Explanation #1]
, , , , , . Therefore, the expectation of is .
[Source]
From the preliminary round of the 2021 Tsinghua University Student Algorithm Contest and Collegiate Invitational (THUPC2021).
Resources such as the editorial can be found at https://github.com/THUSAAC/THUPC2021-pre.
Translated by ChatGPT 5
京公网安备 11011102002149号