#P6034. Ryoku 与最初之人笔记

Ryoku 与最初之人笔记

Description

Ryoku retold the problem to you: compute:

$$\sum_{a = 0}^n \sum_{b = a + 1}^n [a\equiv b\pmod {a \text{ xor } b}]$$

That is, count the number of ordered pairs (a,b)(a,b) such that ab(moda xor b)a\equiv b\pmod {a \text{ xor } b}, where a,ba,b are non-negative integers not greater than nn, and a<ba<b.

Input Format

The input contains one integer nn.

Output Format

Output one integer, the value of the expression above, modulo 109+710^9 + 7.

2
2
42
274

Hint

[Sample 1 Explanation]

The pairs (a,b)(a,b) that satisfy the condition are: (0,1),(0,2)(0,1), (0,2).


[Constraints]

For 20%20\% of the testdata, n103n\le 10^3.
For 60%60\% of the testdata, n106n\le 10^6.
For 70%70\% of the testdata, n109n\le 10^9.
For 100%100\% of the testdata, 2n10182\le n \le 10^{18}.

Translated by ChatGPT 5