mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-12 17:49:50 +00:00
Update power.py
This commit is contained in:
parent
9e6c74cd9f
commit
fcf7918374
@ -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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user