Last active
March 17, 2019 07:01
-
-
Save pysoftware/a1b74b73161200b7626c17baff5e7c3d to your computer and use it in GitHub Desktop.
Recursion exponentiation/ Рекусивное воезведение в степень
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Recursion exponentiation | |
# Рекурсивное возведение в степень | |
def fast_power(a,b): | |
# Базовый случай | |
if b == 0: return 1 | |
if b % 2 == 1: | |
return a * fast_power(a, b-1) | |
else: | |
return fast_power(a*a, b//2) | |
def fast_power2(a,b): | |
# Базовый случай | |
if b == 0: return 1 | |
else: | |
if n%2 == 0: | |
return fast_power2(a,b//2) ** 2 | |
else: | |
return fast_power2(a, b-1)*a | |
a, b = map(int, input().split()) | |
print(fast_power(a, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment