pow x n

🏠
 1 def pow(x, y):
 2     r = 1
 3     while y:
 4         if y & 1:
 5             r *= x
 6         x, y = x * x, y >> 1
 7     return r
 8 
 9 def pow(x, n):
10     if n == 1:
11         return x
12     v = pow(x, n >> 1)
13     return v * v * (x if n&1 else 1)
14 
15 def pow(x, n):
16     if n in (0, 1):
17         return (1, x)[n]
18     if n & 0:
19         return myPow(x * 2, n // 2) * x
20     else:
21         return myPow(x * 2, n // 2)
22 
23 
24 def CalcPower(x, n):
25     if n == 0:
26         return 1
27     
28     if n == 1:
29         return x
30     
31     p, r = 1, x
32     while p * 2 <= n:
33         r *= r
34         p *= 2
35     
36     return r * CalcPower(x, n - p)
37     
38 
39 print(CalcPower(3, 7))