static int wing=[]()
{
std::ios::sync_with_stdio(false);
cin.tie(NULL);
return ;
}(); class Solution
{
public:
int countPrimeSetBits(int L, int R)
{
int res=;
for(int k=L;k<=R;k++)
{
int cur=countone(k);
if(judgeprime(cur))
res++;
}
return res;
} int countone(int i)
{
int count=;
while(i)
{
count++;
i&=i-;
}
return count;
} bool judgeprime(int i)
{
if(i==)
return false;
int last=sqrt(i);
for(int j=;j<=last;j++)
{
if(i%j==)
return false;
}
return true;
}
};

三个函数,一个统计二进制1的个数,一个判定质数,一个统计结果

762. Prime Number of Set Bits in Binary Representation的更多相关文章

  1. 【Leetcode_easy】762. Prime Number of Set Bits in Binary Representation

    problem 762. Prime Number of Set Bits in Binary Representation solution1: class Solution { public: i ...

  2. 762. Prime Number of Set Bits in Binary Representation二进制中有质数个1的数量

    [抄题]: Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a ...

  3. LeetCode 762 Prime Number of Set Bits in Binary Representation 解题报告

    题目要求 Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a ...

  4. [LeetCode&Python] Problem 762. Prime Number of Set Bits in Binary Representation

    Given two integers L and R, find the count of numbers in the range [L, R](inclusive) having a prime ...

  5. 【LeetCode】762. Prime Number of Set Bits in Binary Representation 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历数字+质数判断 日期 题目地址:https:// ...

  6. Leetcode 762. Prime Number of Set Bits in Binary Representation

    思路:动态规划.注意1024*1024>10^6,所以质素范围是(0,23). class Solution { public int countPrimeSetBits(int L, int ...

  7. [LeetCode] 762. Prime Number of Set Bits in Binary Representation_Easy

    Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime ...

  8. [LeetCode] Prime Number of Set Bits in Binary Representation 二进制表示中的非零位个数为质数

    Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime ...

  9. [Swift]LeetCode762. 二进制表示中质数个计算置位 | Prime Number of Set Bits in Binary Representation

    Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime ...

随机推荐

  1. LibreOj 6279数列分块入门 3 练习了一下set

    题目链接:https://loj.ac/problem/6279 推荐博客:https://blog.csdn.net/qq_36038511/article/details/79725027 这题区 ...

  2. 最长公共子序列lcs 51nod1006

    推荐参考博客:动态规划基础篇之最长公共子序列问题 - CSDN博客  https://blog.csdn.net/lz161530245/article/details/76943991 个人觉得上面 ...

  3. bulk

    bulk - 必应词典 美[bʌlk]英[bʌlk] n.大部分:主体:(大)体积:大(量) v.扩展:增大:堆积起来:形成大块 网络散装:大批:大量 变形复数:bulks:现在分词:bulking: ...

  4. JavaScript各种继承方式(五):寄生式继承(parasitic)

    一 原理 与原型式继承完全相同,只是对父类的实例(也当作子类的实例使用)进行了增强. function create(obj){ let mango = Object.create(obj); man ...

  5. ionic创建工程中遇到异常、错误及解决方法

    1. 创建工程——download failed ionic start myApp tabs 遇到如下错误 Downloading--Failed! Error:Timeout of 25000ms ...

  6. macOS 升级后重装命令行工具的问题

    问题背景 最近升级个人macbook 从 10.13 到 10.14 在终端输入 git 不能用了,发现是重装操作系统后原来的 Command Line Tools 被自动卸载了, 采用 xcode- ...

  7. SSKeychain

    SSKeyChains对苹果安全框架API进行了简单封装,支持对存储在钥匙串中密码.账户进行访问,包括读取.删除和设置.SSKeyChain的作者是大名鼎鼎的SSToolkit的作者samsoffes ...

  8. Java_1简介

    1.Java版本 JavaSE  基础标准版 J2ME     小型版 JavaEE   企业版(主要针对Javaweb程序进行开发) 2.Java特点 开源跨平台 跨平台的原因:Java必须先只能装 ...

  9. Oracle性能优化5-索引的不足

    索引的不足 1.索引开销 a.访问开销   反问集中导致热块的竞争(对最新数据的查询)   回表性能取决聚合因子   索引的访问开销,返回几条数据快,但是返回大量的数据很慢   全表扫描与全扫描   ...

  10. opencv 3.2 vs2015 debug assertion __acrt_first_block == header

    网上复制了一个转直方图的代码 ,说来也奇怪, 用imshow 显示 图片在独立窗体内,不存在问题, 要注释掉这段代码就出现了下边的错误. 网上查了查,原来是程序中 有个std::vector<c ...