762. Prime Number of Set Bits in Binary Representation Easy
1/**
2 * [762] Prime Number of Set Bits in Binary Representation
3 *
4 * 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.
5 * Recall that the number of set bits an integer has is the number of 1's present when written in binary.
6 *
7 * For example, 21 written in binary is 10101, which has 3 set bits.
8 *
9 *
10 * Example 1:
11 *
12 * Input: left = 6, right = 10
13 * Output: 4
14 * Explanation:
15 * 6 -> 110 (2 set bits, 2 is prime)
16 * 7 -> 111 (3 set bits, 3 is prime)
17 * 8 -> 1000 (1 set bit, 1 is not prime)
18 * 9 -> 1001 (2 set bits, 2 is prime)
19 * 10 -> 1010 (2 set bits, 2 is prime)
20 * 4 numbers have a prime number of set bits.
21 *
22 * Example 2:
23 *
24 * Input: left = 10, right = 15
25 * Output: 5
26 * Explanation:
27 * 10 -> 1010 (2 set bits, 2 is prime)
28 * 11 -> 1011 (3 set bits, 3 is prime)
29 * 12 -> 1100 (2 set bits, 2 is prime)
30 * 13 -> 1101 (3 set bits, 3 is prime)
31 * 14 -> 1110 (3 set bits, 3 is prime)
32 * 15 -> 1111 (4 set bits, 4 is not prime)
33 * 5 numbers have a prime number of set bits.
34 *
35 *
36 * Constraints:
37 *
38 * 1 <= left <= right <= 10^6
39 * 0 <= right - left <= 10^4
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/
45// discuss: https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn count_prime_set_bits(left: i32, right: i32) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_762() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.