rust 19ms solution with explain
\n\n# Approach\nThe question does\'t rely on the order of the number, or it\'s frequency. In fact, the multiple appearance of a number will cause a trouble. The
![image.png](https://assets.leetcode.com/users/images/ccb60c37-3fbe-40f4-9d51-a074427fed82_1712884963.8739526.png)\n\n# Approach\nThe question does\'t rely on the order of the number, or it\'s frequency. In fact, the multiple appearance of a number will cause a trouble. The first step would be change the vec into a set.\n\nRead this truth table.\n\n| A | B |A&B + A\\|B|\n|:-:|:-:|:--------:|\n|0|0|0|\n|0|1|1|\n|1|0|1|\n|1|1|2|\n\nSo the sum required in the question is the sum of (how many 1 the binary of the the number have), or popcount, of the two number.\n\nThe question becomes counting how many (a, b) so that popcount(a)+popcount(b)>=k. This is an easy-level question.\n\n# Complexity\n- Time complexity:\n$$O(n)$$\n\n- Space complexity:\n$$O(n)$$\n\n# Code\n```\nuse std::collections::HashSet;\nimpl Solution {\n    pub fn count_excellent_pairs(nums: Vec<i32>, k: i32) -> i64 {\n        let k=k as usize;\n        let s:HashSet<i32>=HashSet::from_iter(nums.iter().cloned());\n        let mut n=[0i64; 33];\n        let mut m=0;\n        for i in s{\n            let t=i.count_ones() as usize;\n            n[t]+=1;\n            if t>m{m=t;}\n        }\n        let mut res=0;\n        for i in 0..=m{\n            for j in 0..=m{\n                if i+j>=k{\n                    res+=n[i]*n[j];\n                }\n            }\n        }\n        res\n    }\n}\n```
['Rust']