luogu#P5177. 签到

签到

Background

Solution: https://blog.csdn.net/kkkksc03/article/details/85008142

Problem Description

Compute $\sum_{i=1}^n \sum_{j=1}^n i \ xor \ j \in [\min(i,j),\max(i,j)]$.

Since the answer may be very large, output the value modulo 109+710^9+7.

Input Format

The first line contains an integer TT, the number of test cases.

The next TT lines each contain one integer nn.

Output Format

For each test case, output the answer.

3
10
100
1000
20
2634
325502

Hint

Explanation for the first sample:

There are 2020 pairs (i,j)(i,j) that satisfy the condition.

i=1  j=3  i^j=2
i=1  j=5  i^j=4
i=1  j=7  i^j=6
i=1  j=9  i^j=8
i=2  j=6  i^j=4
i=2  j=7  i^j=5
i=2  j=10  i^j=8
i=3  j=1  i^j=2
i=3  j=6  i^j=5
i=3  j=7  i^j=4
i=3  j=10  i^j=9
i=5  j=1  i^j=4
i=6  j=2  i^j=4
i=6  j=3  i^j=5
i=7  j=1  i^j=6
i=7  j=2  i^j=5
i=7  j=3  i^j=4
i=9  j=1  i^j=8
i=10  j=2  i^j=8
i=10  j=3  i^j=9

Constraints:

For 27%27\% of the testdata, T5T\le 5, n1000n \le 1000.

For 54%54\% of the testdata, T20T\le 20, n5×105n \le 5 \times 10^5.

For 90%90\% of the testdata, T105T\le 10^5, n1018n \le 10^{18}.

For the last test point, T=3×106 , n1018T=3\times 10^6 \ ,\ n\le 10^{18}.

Translated by ChatGPT 5