欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1843C.Sum in Binary Tree
Sum in Binary Tree
Vanya really likes math. One day when he was solving another math problem, he came up with an interesting tree. This tree is built as follows.
Initially, the tree has only one vertex with the number — the root of the tree. Then, Vanya adds two children to it, assigning them consecutive numbers — and , respectively. After that, he will add children to the vertices in increasing order of their numbers, starting from , assigning their children the minimum unused indices. As a result, Vanya will have an infinite tree with the root in the vertex , where each vertex will have exactly two children, and the vertex numbers will be arranged sequentially by layers.
Part of Vanya's tree.
Vanya wondered what the sum of the vertex numbers on the path from the vertex with number to the vertex with number in such a tree is equal to. Since Vanya doesn't like counting, he asked you to help him find this sum.
Input
The first line contains a single integer () — the number of test cases.
This is followed by lines — the description of the test cases. Each line contains one integer () — the number of vertex for which Vanya wants to count the sum of vertex numbers on the path from the root to that vertex.
Output
For each test case, print one integer — the desired sum.
Note
In the first test case of example on the path from the root to the vertex there are two vertices and , their sum equals .
In the second test case of example on the path from the root to the vertex with number there are vertices , , , , sum of their numbers equals .
Samples
6
3
10
37
1
10000000000000000
15
4
18
71
1
19999999999999980
26
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |