Advertisement
pavelperc

Untitled

Dec 20th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. def fast_pow(a, n):
  2.     if n < 0:
  3.         return 1 / fast_pow(a, -n)
  4.  
  5.     if n == 0:
  6.         return 1
  7.     if n % 2:
  8.         return a * fast_pow(a, n - 1)
  9.     else:
  10.         return fast_pow(a * a, n / 2)
  11.  
  12.  
  13. a = float(input())
  14. n = int(input())
  15.  
  16. print(fast_pow(a, n))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement