762. Prime Number of Set Bits in Binary Representation
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的更多相关文章
- 【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 ...
- 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 ...
- 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 ...
- [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 ...
- 【LeetCode】762. Prime Number of Set Bits in Binary Representation 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历数字+质数判断 日期 题目地址:https:// ...
- Leetcode 762. Prime Number of Set Bits in Binary Representation
思路:动态规划.注意1024*1024>10^6,所以质素范围是(0,23). class Solution { public int countPrimeSetBits(int L, int ...
- [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 ...
- [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 ...
- [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 ...
随机推荐
- Mac快捷键大全
Android Studio command+option+L:格式化代码 Visual Studio Code option+shift+f:格式化代码 先按command+k,再按command+ ...
- Tomcat端口的改变和编码的设置
1.更改默认的端口: 在默认情况下,tomcat的端口是8080,如果出现8080端口号冲突,用如下方法可以修改Tomcat的端口号: 首先: 在Tomcat的根(安装)目录下,有一个conf文件夹, ...
- centos7 二进制版本安装 mysql8.0.13
一.下载mysql二进制安装包 mysql官网: https://dev.mysql.com/downloads/mysql/ 由于国内网络问题,个人建议使用国内开源镜像站下载: http://mir ...
- docker-ce-17.09 数据卷和数据卷容器
docker容器中管理数据两种方式:1.数据卷(Data Volumes)2.数据卷容器(Data Volume Dontainers) 一.数据卷特性:1.数据卷可以在容器之间共享和重用2.对数据卷 ...
- BOM浏览器对象模型;
1.window.open(url,ways) url是打开的网页地址 ways是打开方式(-blank:-self) 2.window.close()关闭窗口 3.浏览器的用户信息 window.n ...
- c#按照回车换行符分割字符串
string str="aaa\r\nbbscccjdddseee"; string[] sArray=str.Split(new char[2] {'\r','\n'}); 和用 ...
- EmguCV Image类中的函数(二)使用MorphologyEx进行更多的变换
MorphologyEx中所有的变换如下图所示 调用方法: Mat aaa = CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.R ...
- Oracle_SQL(6) 单行函数
一.单行函数1.定义:对表或视图的查询时,针对每行记录返回一个值的函数.2.用途:用于select语句,where条件3.分类: 数值函数 Number Functions 字符函数(返回字符) Ch ...
- 转::before和::after伪元素的用法
一.介绍 css3为了区分伪类和伪元素,伪元素采用双冒号写法. 常见伪类——:hover,:link,:active,:target,:not(),:focus. 常见伪元素——::first-let ...
- poj 1088 (dfs+记忆化) 滑雪
题目;http://poj.org/problem?id=1088 感觉对深搜还不太熟练,所以练习一下,类似于连连看的那题,注意的是所求的是最大达长度,并不是从最大的或者最小的点出发得到的就是最长的路 ...