首页 > 其他 > 详细

762. 二进制表示中质数个计算置位

时间:2020-04-17 12:15:26      阅读:68      评论:0      收藏:0      [点我收藏+]
 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 };

 

762. 二进制表示中质数个计算置位

原文:https://www.cnblogs.com/yuhong1103/p/12718456.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!