链接:https://www.nowcoder.com/acm/contest/142/C
来源:牛客网
题目描述
Chiaki is interested in an infinite sequence a1, a2, a3, ..., which defined as follows:
Chiaki would like to know the sum of the first n terms of the sequence, i.e.
. As this number may be very large, Chiaki is only interested in its remainder modulo (109 + 7).
输入描述:
There are multiple test cases. The first line of input contains an integer T (1 ≤ T ≤ 105), indicating the number of test cases. For each test case:
The first line contains an integer n (1 ≤ n ≤ 1018).
输出描述:
For each

博客介绍了 Chiaki 定义的一个无限序列,其规律为根据二进制中相邻位数值关系确定项的增减。题目要求计算前 n 项和对 (10^9 + 7) 取模的结果。通过观察二进制模式,可以采用数位动态规划的方法解决,其中 dp[i][j][k] 表示第 i 位,当前位值为 j,总和为 k 的状态。考虑到和的范围,使用绝对值简化表示。博客提供了详细的解题思路和参考链接。
最低0.47元/天 解锁文章
1042





