Skip to content

Instantly share code, notes, and snippets.

@pysoftware
Last active March 17, 2019 07:01
Show Gist options
  • Save pysoftware/a1b74b73161200b7626c17baff5e7c3d to your computer and use it in GitHub Desktop.
Save pysoftware/a1b74b73161200b7626c17baff5e7c3d to your computer and use it in GitHub Desktop.
Recursion exponentiation/ Рекусивное воезведение в степень
# 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