mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 19:53:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给你两个整数 <code>left</code> 和 <code>right</code> ,在闭区间 <code>[left, right]</code> 范围内,统计并返回 <strong>计算置位位数为质数</strong> 的整数个数。</p>
 | 
						||
 | 
						||
<p><strong>计算置位位数</strong> 就是二进制表示中 <code>1</code> 的个数。</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>例如, <code>21</code> 的二进制表示 <code>10101</code> 有 <code>3</code> 个计算置位。</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>left = 6, right = 10
 | 
						||
<strong>输出:</strong>4
 | 
						||
<strong>解释:</strong>
 | 
						||
6 -> 110 (2 个计算置位,2 是质数)
 | 
						||
7 -> 111 (3 个计算置位,3 是质数)
 | 
						||
9 -> 1001 (2 个计算置位,2 是质数)
 | 
						||
10-> 1010 (2 个计算置位,2 是质数)
 | 
						||
共计 4 个计算置位为质数的数字。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>left = 10, right = 15
 | 
						||
<strong>输出:</strong>5
 | 
						||
<strong>解释:</strong>
 | 
						||
10 -> 1010 (2 个计算置位, 2 是质数)
 | 
						||
11 -> 1011 (3 个计算置位, 3 是质数)
 | 
						||
12 -> 1100 (2 个计算置位, 2 是质数)
 | 
						||
13 -> 1101 (3 个计算置位, 3 是质数)
 | 
						||
14 -> 1110 (3 个计算置位, 3 是质数)
 | 
						||
15 -> 1111 (4 个计算置位, 4 不是质数)
 | 
						||
共计 5 个计算置位为质数的数字。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= left <= right <= 10<sup>6</sup></code></li>
 | 
						||
	<li><code>0 <= right - left <= 10<sup>4</sup></code></li>
 | 
						||
</ul>
 |