Update power.py

This commit is contained in:
lighting9999 2025-02-08 18:16:12 +08:00 committed by GitHub
parent 9e6c74cd9f
commit fcf7918374
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
def actual_power(a: int, b: int): def actual_power(a: int, b: int)-> int:
""" """
Function using divide and conquer to calculate a^b. Function using divide and conquer to calculate a^b.
It only works for integer a,b. It only works for integer a,b.
@ -22,9 +22,9 @@ def actual_power(a: int, b: int):
half = actual_power(a, b // 2) half = actual_power(a, b // 2)
if (b % 2) == 0: if (b % 2) == 0:
return actual_power(a, int(b / 2)) * actual_power(a, int(b / 2))
else:
return half * half return half * half
else:
return a * half * half
def power(a: int, b: int) -> float: def power(a: int, b: int) -> float: