Skip to content

Commit 3192870

Browse files
authored
Create exponentiation.py
1 parent 6275d95 commit 3192870

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

exponentiation.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'''Efficient approach'''
2+
3+
def bin_pow(a,n):
4+
res = 1
5+
while(n>0):
6+
if n&1:
7+
res = res * a
8+
a = a * a
9+
n >>= 1
10+
return res
11+
print(bin_pow(2101010,32)) #20782597351780148360705447543438026166282198412508937706220746225693908693563681788663888827908012942663696008670876015403914749631306435949260373147394419808970340368320100000000000000000000000000000000
12+
13+
''' Time complexity : O(log n) '''

0 commit comments

Comments
 (0)