MCPcopy Create free account
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / power

Function power

divideAndConquer.py:21–28  ·  view source on GitHub ↗
(base, x)

Source from the content-addressed store, hash-verified

19
20# 分治法计算正整数幂
21def power(base, x):
22 if x == 1:
23 return base
24 else:
25 if x & 1 == 1:
26 return power(base, x>>1)*power(base, x>>1)*base
27 else:
28 return power(base, x>>1)*power(base, x>>1)
29
30print(power(2, 6))

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected