1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/二进制表示中质数个计算置位 [prime-number-of-set-bits-in-binary-representation].html
2022-03-29 12:43:11 +08:00

47 lines
1.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你两个整数&nbsp;<code>left</code>&nbsp;&nbsp;<code>right</code> ,在闭区间 <code>[left, right]</code>&nbsp;范围内,统计并返回 <strong>计算置位位数为质数</strong> 的整数个数。</p>
<p><strong>计算置位位数</strong> 就是二进制表示中 <code>1</code> 的个数。</p>
<ul>
<li>例如, <code>21</code>&nbsp;的二进制表示&nbsp;<code>10101</code>&nbsp;<code>3</code> 个计算置位。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>left = 6, right = 10
<strong>输出:</strong>4
<strong>解释:</strong>
6 -&gt; 110 (2 个计算置位2 是质数)
7 -&gt; 111 (3 个计算置位3 是质数)
9 -&gt; 1001 (2 个计算置位2 是质数)
10-&gt; 1010 (2 个计算置位2 是质数)
共计 4 个计算置位为质数的数字。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>left = 10, right = 15
<strong>输出:</strong>5
<strong>解释:</strong>
10 -&gt; 1010 (2 个计算置位, 2 是质数)
11 -&gt; 1011 (3 个计算置位, 3 是质数)
12 -&gt; 1100 (2 个计算置位, 2 是质数)
13 -&gt; 1101 (3 个计算置位, 3 是质数)
14 -&gt; 1110 (3 个计算置位, 3 是质数)
15 -&gt; 1111 (4 个计算置位, 4 不是质数)
共计 5 个计算置位为质数的数字。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= left &lt;= right &lt;= 10<sup>6</sup></code></li>
<li><code>0 &lt;= right - left &lt;= 10<sup>4</sup></code></li>
</ul>