<p>我正在编写一个简单的算法来检查整数的素性,我在将Java代码转换为Python时遇到了问题:</p>
<pre class="lang-java prettyprint-override"><code>for (int i = 3; i < Math.sqrt(n); i += 2) {
if (n % i == 0)
return false;
}
</code></pre>
<p>所以,我一直在试着用这个,但很明显我跳过了3分:</p>
<pre class="lang-py prettyprint-override"><code>i = 3
while (i < int(math.sqrt(n))):
i += 2 # where do I put this?
if (n % i == 0):
return False
</code></pre>