Numbers with exactly two set bits
How many integers with have exactly two set bits in their binary representation (i.e. popcount(n) == 2)?
Show hints (2)+
- Two set bits for distinct positions - count the pairs, don't scan.
- Usable positions are (since ); every pair , so the answer is .
Answer
Reveal answer →Final answer
21
Want the full step-by-step worked solution? It's part of Premium - along with a worked solution for every question in the bank.
Asked at: Game-Based Aptitude, Mixed Quant & Coding