思路:动态规划。注意1024*1024>10^6,所以质素范围是(0,23)。

 class Solution {
public int countPrimeSetBits(int L, int R) {
Set<Integer> prime = new HashSet<Integer>(Arrays.asList(2,3,5,7,11,13,17,19,23));
int[] count = new int[1+R];
int res = 0;
for(int i = 1; i <=R; i++) count[i] = count[i>>1] + (i&1);
for(int i = L; i <=R; i++) {
if(prime.contains(count[i])) res++;
}
return res;
}
}

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

  1. 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 ...

  2. 【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 ...

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

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

  4. [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 ...

  5. [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 ...

  6. 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 ...

  7. 762. Prime Number of Set Bits in Binary Representation

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  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. 分离 桂林电子科技大学第三届ACM程序设计竞赛

    链接:https://ac.nowcoder.com/acm/contest/558/H 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...

  2. Intellij IDEA 14的注册机(Java版)

    import java.math.BigInteger; import java.util.Date; import java.util.Random; import java.util.zip.CR ...

  3. Moving XML/BI Publisher Components Between Instances

    As it is well known fact that XMLPublisher stores the metadata and physical files for templates and ...

  4. mac下能同时安装两个版本的xcode吗

    http://www.cocoachina.com/bbs/read.php?tid-288160-page-1.html

  5. [Openwrt 项目开发笔记]:USB挂载& U盘启动(三)

    [Openwrt项目开发笔记]系列文章传送门:http://www.cnblogs.com/double-win/p/3888399.html 正文: 在上一篇中,我结合Netgear Wndr370 ...

  6. Autofac创建实例的方法总结[转]

    1.InstancePerDependency 对每一个依赖或每一次调用创建一个新的唯一的实例.这也是默认的创建实例的方式. 官方文档解释:Configure the component so tha ...

  7. [翻译]ASP.NET Web API 2 中的全局错误处理

    目录 已存在的选项 解决方案预览 设计原则 什么时候去用 方案详情 示例 附录: 基类详情 原文链接 Global Error Handling in ASP.NET Web API 2 由于翻译水平 ...

  8. 编码CODING

    摘自(复制)于海燕博客: http://www.cnblogs.com/haiyan123/p/7230533.html 1.内存和硬盘都是用来存储的. CPU:速度快 硬盘:永久保存 2.文本编辑器 ...

  9. day 113 爬虫框架

    基础配置

  10. Flask系列02--Flask中的request

    一.Flask中的request方法 1.数据相关 #flask中request,render_template等方法要通过引包的方式引入 from flask import request ​ re ...