This commit is contained in:
krahets
2023-07-26 08:59:03 +08:00
parent fd34c845bc
commit 974fea7de4
48 changed files with 299 additions and 299 deletions
@@ -3588,7 +3588,7 @@ n = 3 a + b
<p><strong>时间复杂度取决于编程语言的幂运算的实现方法</strong>。以 Python 为例,常用的幂计算函数有三种:</p>
<ul>
<li>运算符 <code>**</code> 和函数 <code>pow()</code> 的时间复杂度均为 <span class="arithmatex">\(O(\log a)\)</span> </li>
<li>运算符 <code>**</code> 和函数 <code>pow()</code> 的时间复杂度均为 <span class="arithmatex">\(O(\log a)\)</span> </li>
<li>函数 <code>math.pow()</code> 内部调用 C 语言库的 <code>pow()</code> 函数,其执行浮点取幂,时间复杂度为 <span class="arithmatex">\(O(1)\)</span></li>
</ul>
<p>变量 <span class="arithmatex">\(a\)</span> , <span class="arithmatex">\(b\)</span> 使用常数大小的额外空间,<strong>因此空间复杂度为 <span class="arithmatex">\(O(1)\)</span></strong></p>