[Leetcode] 762. Prime Number of Set Bits in Binary Representation

LeetCode --- 762. Prime Number of Set Bits in Binary Representation 解题报告 Given two integersLandR, find the count of numbers in the range[L, R](inclusive) having a prime number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of1s present when written in binary. ... 阅读详情

Description:

Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation.

(Recall that the number of set bits an integer has is the number of 1s present when written in binary. For example, 21 written in binary is 10101 which has 3 set bits. Also, 1 is not a prime.)

 

Example 1:

Input: L = 6, R = 10
Output: 4
Explanation:
6 -> 110 (2 set bits, 2 is prime)
7 -> 111 (3 set bits, 3 is prime)
9 -> 1001 (2 set bits , 2 is prime)
10->1010 (2 set bits , 2 is prime)

Example 2:

Input: L = 10, R = 15
Output: 5
Explanation:
10 -> 1010 (2 set bits, 2 is prime)
11 -> 1011 (3 set bits, 3 is prime)
12 -> 1100 (2 set bits, 2 is prime)
13 -> 1101 (3 set bits, 3 is prime)
14 -> 1110 (3 set bits, 3 is prime)
15 -> 1111 (4 set bits, 4 is not prime)

Note:

  1. L, R will be integers L <= R in the range [1, 10^6].
  2. R - L will be at most 10000.

 

 

class Solution {
    public int countPrimeSetBits(int L, int R) {
        int result = 0;
        for (int i = L; i <=R; i++){
            String a = Integer.toBinaryString(i);
            int sum = 0;
            boolean decide = true;
            
            for (int j = 0; j < a.length(); j++) {
                char c = a.charAt(j);
                if (c == '1')
                    sum++;
            }
            if(sum == 2) 
                decide = true;
            else if(sum < 2 || sum % 2 == 0) 
                decide = false;
            for(int k=3; k<=Math.sqrt(sum); k+=2){
                if(sum % k == 0)
                    decide = false;
                
            }
            if (decide == true)
                result = result + 1;
        }
        return result;
    }
}

 

分别使用了十进制转二进制,以及质数判断 两个算法

ceph recovery 相关参数 可以修改的最大回填/恢复选项列在 “恢复/回填选项” 部分。mClock 的修改 默认回填/恢复限制由 osd_mclock_override_recovery_settings 选项,设置为 默认为 false。尝试修改任何默认恢复/回填限制而不设置门控选项,会将该选项重置为 mClock 默认值,并在集群日志中记录一条警告消息。请注意,默认值可能需要几秒钟才能恢复生效。请使用 config show 命令验证限制,如下所示。就直接设置以下参数,过一会就变回了默认值。简单点说官网的意思就是不设置。 阅读详情

相关推荐

PRD撰写效率翻倍秘籍:我是如何用大模型+飞书文档搭建自动化工作流的

本文分享了如何利用大模型与飞书文档构建自动化工作流,以大幅提升PRD撰写效率。通过结构化需求输入、设计模块化提示词模板,并借助自动化脚本桥接数据与文档,产品经理可将繁琐的文档撰写工作自动化,从而将精力聚焦于产品战略与用户洞察。

weixin_28520495的博客 408

LeetCode 693. Binary Number with Alternating Bits

题目描述:判断某个二进制位是否为交替1010101的特征数。 题目链接:693. Binary Number with Alternating Bits 思路:设置一个标志位,然后记录上一位的数,如果下一个位还是如此,就返回False,当然也哈有很多奇妙的解法。例如:移位相加后为0,或者右移二位异或,都是根据交替的特点来进行盐酸的方法。 参考链接 LeetCode 693. Binary N...

Za七杂⑧ 229

用Multisim和74192芯片复刻经典:手把手教你搭建篮球24秒违例计时器(附仿真文件)

本文详细介绍了如何使用Multisim仿真平台和74192芯片构建篮球24秒违例计时器,涵盖时序逻辑电路设计、核心器件选型、仿真环境搭建及调试技巧。通过分步指导,帮助读者掌握数字电路设计的关键技术,并附赠仿真文件供实践参考。

weixin_27014595的博客 279

练习9(数论初步)

A - 整除的尾数 一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢? Input输入数据有若干组,每组数据包含二个整数a,b(0 Output对应每组数据,将满足条件的所有尾数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。 Sample Input 200 40 1992 95 0

qq_26973089的博客 1399

YOLO v11添加ap75指标

yolov11添加ap75指标,yolo系列添加ap75指标

zf_14159265358979的博客 1892

PLC期末速成——顺序功能图转梯形图

一、根据顺序功能图写出梯形图程序 顺序功能图: 梯形图: 1、程序段1,系统运行标志M0.0的启-保-停控制电路。 2、程序段2,PLC上电与逆行,初始化脉冲M1.0激活初始化步M2.0。 3、程序段3,当M2.0初始化步为活动步,并且M0.0系统运行标志位为1时,置位M2.1步,复位M2.0步。 4、当M2.1为活动步,并且I0.3中液位传感器为1时,置位M2.2步,复位M2.1步。 5、程序段5,当M2.2为活动步,并且I0.2高液位传感器为1时,置位M2.3步,复位M2.2步。 6、程序段

qq_52251819的博客 1万+

水题(5)计算题

目录 CSU 1035Max DPS CSU 1040 Round-number CSU 1042 遥控机器人 CSU 1114 平方根大搜索 CSU 1131 Nim-B* Sum (求B进制的异或和) CSU 1155 |a-b| CSU1160 十进制-十六进制 CSU 1163 寒衣调 CSU 1205 Rectangles II CSU 1212 中位数 CSU1215 稳定排序 CSU 1240 低调,低调。(异或找出2个只出现1次...

nameofcsdn的博客 3768

白话机器学习算法理论+实战番外篇之Xgboost

1. 写在前面 如果想从事数据挖掘或者机器学习的工作,掌握常用的机器学习算法是非常有必要的,在这简单的先捋一捋, 常见的机器学习算法: 监督学习算法:逻辑回归,线性回归,决策树,朴素贝叶斯,K近邻,支持向量机,集成算法Adaboost等 无监督算法:聚类,降维,关联规则, PageRank等 我前面已经尝试用最白话的语言完成了一个白话机器学习算法理论+实战系列,这个系列已经基本包含了上面这些算...

Miracle8070 1万+

[leetcode] 693. Binary Number with Alternating Bits

Description Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Input: 5 Output: True Explanation: The binary re...

Learning from the mistakes 288

在 SAP HANA 里为视图创建 Analytic Privilege,真正把同一份数据按角色切开

摘要:本文介绍了SAP HANA中基于业务角色的动态数据权限控制方法。通过Analytic Privilege技术,可以在同一视图上为不同角色设置不同的数据访问范围,实现行级安全控制。核心机制包括:1) 创建带有STRUCTURED PRIVILEGE CHECK的视图;2) 建立授权对象和用户映射表;3) 开发条件提供过程动态生成过滤条件;4) 创建结构化权限对象绑定条件提供器。这种设计使权限规则与业务数据解耦,便于维护变更,适合销售区域、财务数据等多角色访问控制场景。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 2393

【YOLOv11多模态融合改进】| CVPR2025 LCA轻量交叉注意力 双向模态交叉引导 + 双支路噪点抑制,兼顾纹理与热目标特征融合

可见光模态富含纹理、色彩、边缘细节,但夜间/低照度场景信噪比极低,暗区噪声泛滥;红外模态依靠热辐射凸显弱小目标、暗区物体轮廓,但缺失真实色彩与精细纹理。简单拼接/逐加融合仅做浅层特征叠加,无法建立可见光纹理、红外热特征的双向引导关联,两类模态互补信息无法精准互通;普通自注意力仅单模态内部建模,跨模态交互匮乏,红外热目标易被可见光暗噪声淹没,可见光有效纹理易被红外灰度信息覆盖;

Limiiiing的博客 124

1 异或,两个集合中异或位数最小的

For 2 non-negative integers x and y, f(x, y) is defined as the number of different bits in the binary format of x and y. For example, f(2, 3)=1,f(0, 3)=2, f(5, 10)=4. Now given 2 sets of non-negative...

weixin_44030848的博客 816

LPDDR4 JEDEC标准测试实例解析--写操作

LPDDR4的JEDEC标准一致性测试项详解以及实例分享,满满干货!感兴趣的小伙伴可以持续关注!!

一只豌豆象的博客 7776

LeetCode //C - 762. Prime Number of Set Bits in Binary Representation

This problem requires counting numbers in a given range [left, right] that have a prime number of set bits (1's) in their binary representation. The solution involves three key steps: checking if a number is prime, counting the set bits of a number, and it

Made in Code 1237

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

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

Python版本:python3.6.2 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 number of set b

sunflower_kris的博客 392

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

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

题目地址: https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/ 给定一个正整数区间[L,R][L,R][L,R],问其有多少个整数的二进制表示111的个数是素数。 代码如下: import java.util.Arrays; public class Solution { public int countPrimeSetBits(int L, int R) { boolea

数学、算法爱好者的博客 183

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

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

【LeetCode】762. Prime Number of Set Bits in Binary Representation 解题报告 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/problems/prime-number-of-set-bits-in-binary-representation/description/ 题目描述:

负雪明烛 1895

【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: int countPrimeSetBits(int L, int R) { int res = 0; int bits = 0; ...

weixin_30342827的博客 134

【LeetCode】762. Prime Number of Set Bits in Binary Representation(C++)

地址:https://leetcode.com/problems/reach-a-number 题目: Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representati...

Ethan95的博客 234

[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 prime number of set bits in their binary representation. (Recall that the number of set b

魔豆(Magicbean)的博客 302

python 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 prime number of set bits in their binary representation.(Recall that the number of set bits an integer ha...

DreamerLHQ的博客 419

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

题目链接:二进制表示中质数个计算置位 - 力扣 (LeetCode) Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation. (Recall that ...

zhaohaibo的博客 338

[leetcode]762. Prime Number of Set Bits in Binary Representation

[leetcode]762. Prime Number of Set Bits in Binary Representation Analysis 周一快乐~—— [ummm~] Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime...

weixin_32135877的博客 121

leetcode 762. Prime Number of Set Bits in Binary Representation

基本的代码组合 class Solution { public int countPrimeSetBits(int L, int R) { int count = 0; for(int i=L;i<=R;i++){ int count1 = 0; int tmp = i; whil...

xiaobailaji的博客 130

LeetCode C++ 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 number of set bits in their binary representation. (Recall that the number of set bits an integer has is the number of 1s present when written in binary..

memcpy0的博客 409
上一篇: [Leetcode] 521. Longest Uncommon Subsequence I
下一篇: [Leetcode] 292. Nim Game
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值