luogu#P6034. Ryoku 与最初之人笔记

Ryoku 与最初之人笔记

Background

When Ryoku was reading the notes of the “First Person”, she found an interesting operation: xor\rm xor. This operation takes two numbers as input and outputs one number. It works by converting the two input numbers into binary, then comparing each bit: if the bits are the same, that bit in the output is 00; otherwise it is 11.

Below the notes about the xor\text{xor} operation, there is an exercise. Ryoku quickly got the answer, and she wants to test you.

Problem 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