Numbers with exactly two set bits

How many integers nn with 1n1001 \le n \le 100 have exactly two set bits in their binary representation (i.e. popcount(n) == 2)?

Show hints (2)+
  1. Two set bits =2i+2j= 2^i + 2^j for distinct positions - count the pairs, don't scan.
  2. Usable positions are 0..60..6 (since 27=128>1002^7=128>100); every pair 96\le 96, so the answer is (72)\binom{7}{2}.

Answer

Reveal 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

Related questions