#P7419. 「PMOI-2」参天大树
「PMOI-2」参天大树
Description
b6e0 has a towering tree. This rooted binary tree has infinitely many nodes. The root is numbered . For every , the node numbered has children numbered and .
Among the nodes with numbers , you need to choose two nodes (they may be the same), and find the sum of the numbers of their lowest common ancestors over all choices. That is, compute (where denotes the number of the lowest common ancestor of and ):
It is guaranteed that there exists a natural number such that .
Take the answer modulo .
Input Format
This problem has multiple queries.
The first line contains a positive integer , the number of queries.
The next lines each contain a natural number , meaning that in the -th query .
Output Format
Output lines. The -th line should be the answer for the -th query modulo .
2
2
3
12
88
Hint
[Sample Explanation]
For the first query, , and the answer is .
[Constraints]
This problem uses bundled testdata.
- Subtask 1 (20 pts): .
- Subtask 2 (20 pts): .
- Subtask 3 (20 pts): .
- Subtask 4 (40 pts): no special constraints.
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号