Problems > Numbers with K Set Bits

Numbers with K Set Bits

Difficulty: 1900 5000 ms 128 MB

combinatorics digit-dp

Count the integers in [L, R] whose binary representation has exactly K one-bits.

Input: one line with three integers L, R, K.

Output: the count of integers with popcount K.

Constraints:

  • 1 ≤ L ≤ R ≤ 1018
  • 0 ≤ K ≤ 60

Sample Tests

Input 1
1 10 2
Output 1
5
Input 2
5 5 2
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.