Skip to content

Commit 328fe38

Browse files
Create Binary Exponentiation
1 parent 86f9a6a commit 328fe38

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Diff for: Binary Exponentiation

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//Binary Exponentiation
2+
long long power(long long a, long long b, long long mod = 1e9 + 7){
3+
a = a % mod;
4+
long long ans = 1;
5+
while(b){
6+
if(b & 1)
7+
ans = (ans * a) % mod;
8+
9+
a = a % mod;
10+
a = (a * a) % mod;
11+
b = b / 2;
12+
}
13+
return ans;
14+
}

0 commit comments

Comments
 (0)