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 6281 数列分块入门5

    题目链接:https://loj.ac/problem/6281 参考博客:https://blog.csdn.net/qq_36038511/article/details/79725027 我一开 ...

  2. 对arm裸板调试的理解

    由于arm芯片一般都包含的由jtag调试这项功能,cpu向外部发出信号时,一般都要同jtag发送出去,它就像一个路口的交警一样,能够控制车辆的运行,当然在arm中指的是cpu发出的数据和地址,我们在调 ...

  3. List<Map<String, String>>和Map<String, List<String>>遍历

    public void TestM() {     List<Map<String, String>> lm = new ArrayList<>();     Ma ...

  4. go语言使用go-sciter创建桌面应用(三) 事件处理,函数与方法定义,go与tiscript之间相互调用

    sciter处理脚本tiscript,用于处理UI交互中的一些逻辑,跟js很像,但又有点区别,对前端熟悉的人应该能很快上手. tiscrip脚本文档 https://sciter.com/develo ...

  5. sqlserver数据库的备份与还原——完整备份与还原

    sqlserver提供四种数据库备份方式 完整备份:备份整个数据库的所有内容包括书屋和日志 差异备份:只备份上次完整备份后更高的数据部分 事务日志备份:只备份事务日志里的内容 文件或文件组备份:只备份 ...

  6. 《大道至简》第一章--编程的精意 读后感(JAVA伪代码)

    1. /*愚公移山 原始需求:惩山北之塞,出入之迂: 项目沟通:聚室而谋曰: 项目目标:毕力平险,指通豫南,达于汉阴: 技术方案:扣石垦壤,箕畚运于渤海之尾: 人员构成:愚公率子孙荷担者三夫,邻人京城 ...

  7. 解决 win 7 64 位 vs2010 调试silverlight项目无法加载,提示更新developer ,跟新报 消息 ID: 1517 已安装了 Silverlight 的 64 位版本

    出现上面的问题是我们安装的silverlight的版本和系统给的silverlight下载的版本冲突, 解决的方法是,首先卸载Silverlight runtime(也就是默认的silverlight ...

  8. PAT 1004 成绩排名 (20)(代码)

    1004 成绩排名 (20)(20 分) 读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为\ 第1行:正整数n 第2行:第1 ...

  9. 那些年我们遇到的坑(1)-Description Resource Path Location Type Archive for required library

    在下载JAR包过程中遇到了错误,根据提示找到maven仓库报错的目录,将该目录下的所有文件删除重新下载即可

  10. The 10 Best Choices On The Market Review 2018

    Looking to buy a scan tool or considering one of Autel Scanner impressive product line?. The company ...