No.737 PopCount
Problem Statement
M-san, who loves $1$, defined the beauty $V(x)$ of a natural number $x$ as follows.
- $V(x) = x \times popcount(x)$
Here, $popcount(x)$ is defined as the number of occurrences of $1$ when $x$ is written in base $2$. For example, $popcount(23) = 4$. Written in base $2$, $23$ is $10111$, in which the number of occurrences of $1$ is $4$.
Given a natural number $N$, find $\displaystyle \sum_{i=1}^{N} V(i)$ modulo $10^9+7$.
Input
$N$
A natural number $N(1 \le N \le 10^{18})$ is given on $1$ line.
Output
Output the answer on $1$ line.
Sample
Sample 1
Input
5
Output
23
We have $popcount(1) = 1, popcount(2) = 1, popcount(3) = 2, popcount(4) = 1, popcount(5)=2$.
Since $(1 \times 1) + (2 \times 1) + (3 \times 2) + (4 \times 1) + (5 \times 2) = 23$, the answer is $23$.
Sample 2
Input
30
Output
1333
Sample 3
Input
23072602871
Output
123456789
Note that the input $N$ may not fit in a 32bit integer type, and that the output must be the remainder after division by $10^9+7$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
ei1333333
beet