← All problemsSign in

Pairwise AND

Given a number $N$, consider all whole numbers $\leq N$, ie, $(0, 1, …, N)$. Find the sum of the bitwise AND of all consecutive numbers. For example, the bitwise AND of $5 = 101_2$ and $7 = 111_2$. $(5 \& 7) = (101_2 \& 111_2) = 101_2 = 5$. Since this sum can very large, print the final answer modulo $10^9 + 7$. (Note: Be careful of overflows while dealing with large numbers.) ##

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start