A problem based on a Project Euler question

Правка en1, от ducmatgoctoanlyhoa, 2025-01-22 10:39:08

Hi! I am interested in evaluating this expression:

$$$\displaystyle{\sum_{i=1}^n (i * \text{popcount}(i))^2 \mod (10^9 + 7)}$$$

where $$$\text{popcount}(i)$$$ is the number of 1 digits in the binary expansion of $$$i$$$.

Or, in C++:

int mod = 1e9 + 7;
for (int i = 1; i <= n; ++i){
        // avoid calculating popcount more than once
        g = popcount(i);
        sum += a * a * g * g;
        sum %= mod;
    }
cout << sum;

The problem is that $$$N$$$ is very large ($$$10^{16}$$$). I am completely stuck, so thanks for your help!

Теги math, bitwise operators

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский ducmatgoctoanlyhoa 2025-01-22 10:39:45 0 (published)
en1 Английский ducmatgoctoanlyhoa 2025-01-22 10:39:08 599 Initial revision (saved to drafts)