擅长:python、mysql、java
<p>忽略递归:</p>
<pre><code>n = 6
>>> sum(x ** x for x in range(n, 0, -1))
50069
# 6 ** 6 + 5 ** 5 + 4 ** 4 + 3 ** 3 + 2 ** 2 + 1 ** 1
# = 46656 + 3125 + 356 + 27 + 4 + 1
# = 50069
</code></pre>
<p>使用递归:</p>
<pre><code>def power_function(n):
if n < 1:
return 0
return n ** n + power_function(n - 1)
>>> power_function(6)
50069
</code></pre>