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 ...
随机推荐
- c++面向行的输入getline()和get()
来源:c++ primer plus 在c++里当我们输入一个字符串时习惯用cin,但是cin只能读取一段不含空格的字符串,如果我们需要读取一段包含空格的字符串时,就需要用到getline()或get ...
- Codeforces Beta Round #16 (Div. 2 Only)
Codeforces Beta Round #16 (Div. 2 Only) http://codeforces.com/contest/16 A 水题 #include<bits/stdc+ ...
- F - Restoring the Expression CodeForces - 898F
字符串hash: base设置为10 枚举'='可能出现的位置,从1/2处开始到大概1/3处结束,当然大概的1/3不用计算,直接到最后就行,因为本题必然有解,输出直接结束即可. 根据'='号位置,' ...
- [剑指Offer]快排
快排 看到一篇博文提到"东拆西补"的思想,非常贴切了. 这里采用传统的方法,没有采用剑指Offer书上的方法. 细节很多,需巩固. 其他知识点 生成一个范围内随机数 见代码,这里为 ...
- powerdesigner中实现PDM到MYSQl数据库的转换
一.使用PowerDesigner制作建库脚本 1.设计CDM(Conceptual Data Model) 2.选择 Tools -> Generate Physical Data Model ...
- 序列化、模块 day21
一 序列化 什么叫序列化——将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 字典示例 import json d={'a':1,'b':2} ret = json.dumps(d)# ...
- sql:inner join,left join,right join,full join用法及区别
join的语法: select [字段] from [表名1] inner/left/right/full join [表名2] on [表名1.字段1] <关系运算符> [表名2.字段2 ...
- JAVA程序 从命令行接受多个数字,求和之后输出结果
源程序代码: public class sum{ public static void main(String[] args){ double[] a=new double[4]; a[0]=Doub ...
- iOS.XcodeUsage
1. Customizing Xcode File Templates http://blog.highorderbit.com/2009/03/15/customizing-xcode-cocoa- ...
- 可以搜索局域网内的所有IP地址的软件
几乎都用现有的工具,直接扫描,这里我已python为例,搜索一下局域网内所有活动IP,基本原理就是ping,对返回的结果进行分析,从而判断对应ip是否活动,代码很简单,实验环境win10+python ...