We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9e6c74c commit fcf7918Copy full SHA for fcf7918
divide_and_conquer/power.py
@@ -1,4 +1,4 @@
1
-def actual_power(a: int, b: int):
+def actual_power(a: int, b: int)-> int:
2
"""
3
Function using divide and conquer to calculate a^b.
4
It only works for integer a,b.
@@ -22,9 +22,9 @@ def actual_power(a: int, b: int):
22
half = actual_power(a, b // 2)
23
24
if (b % 2) == 0:
25
- return actual_power(a, int(b / 2)) * actual_power(a, int(b / 2))
26
- else:
27
return half * half
+ else:
+ return a * half * half
28
29
30
def power(a: int, b: int) -> float:
0 commit comments