Prime Number of Set Bits in Binary Representation Problem

Prime Number of Set Bits in Binary Representation Problem — ExecCode Easy DSA Practice

Solve the Prime Number of Set Bits in Binary Representation problem on ExecCode. Free online easy DSA practice in Math. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given two integers left and right, return the count of numbers in the inclusive range [left, right] having a prime number of set bits in their binary representation. Your task is to recall that the number of set bits an integer has is the number of 1's present when written in binary. For example, 21 written in binary is 10101, which has 3 set bits. Return the required answer exactly as shown in the examples.

Examples

Input {"left": 6, "right": 10}; Output 4. Input {"left": 10, "right": 15}; Output 5

Constraints

1 <= left <= right <= 10^6 0 <= right - left <= 10^4

Practice Prime Number of Set Bits in Binary Representation free on ExecCode. Browse DSA problems, topic map, and placement guides.