Skip to content

Commit 2396979

Browse files
authored
Merge pull request #33 from saurabhsingh76/master
Binary Exponentiation algorithm C++
2 parents 2776cb8 + d95a2a3 commit 2396979

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

C++/BinaryExponentiation.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
long long power(long long a, long long b, int mod)
5+
{ long long result = 1;
6+
while(b) {
7+
if(b%2) result=(result*a)%mod;
8+
a=(a*a)%mod;
9+
b/=2;
10+
}
11+
return result;
12+
}
13+
14+
int main()
15+
{
16+
int a = 20, b = 2000000;
17+
int mod = 1e9+7;
18+
cout<<power(a,b,mod);
19+
return 0;
20+
}

0 commit comments

Comments
 (0)