擅长:python、mysql、java
<p>在python3中的代码不应该出现内存问题。我试过了(把<code>xrange()</code>改成<code>range()</code>),在12秒内得到了响应。你知道吗</p>
<p>你可以这样写函数:</p>
<pre><code>def Thermo_Only(n):
return [ (1<<i)-1 for i in range(0,3*n,3) ]
</code></pre>
<p>这实际上允许您完全避免生成列表。如果要将结果放入数组中:</p>
<pre><code>thermoArray = Thermo_Only(n)
</code></pre>
<p>您只需创建一个函数,并像引用数组中的索引一样使用它:</p>
<pre><code>def thermoArray(n): return (1<<(3*n))-1
</code></pre>
<p>在代码中使用<code>thermoArray(i)</code>而不是<code>thermoArray[i]</code>。你知道吗</p>