1 class Solution 2 { 3 public: 4 unordered_set<int> hash = {2,3,5,7,11,13,17,19}; 5 int countPrimeSetBits(int L, int R) 6 { 7 int res = 0; 8 for(int i = L;i <= R;i ++) 9 { 10 int count = 0; 11 for(int j = 0;j < 20;j ++) //2^20 = 1048576 12 { 13 count += i >> j & 1; 14 } 15 if(hash.find(count) != hash.end()) res ++; 16 } 17 return res; 18 } 19 };
原文:https://www.cnblogs.com/yuhong1103/p/12718456.html