Skip to content

Commit

Permalink
Create ppbra.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
bazzil29 authored and yshshrm committed Oct 31, 2018
1 parent a4c487e commit ac97dbe
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cpp/algorithms/ppbra.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Modular_Exponentiation(ll A,ll B,ll MOD)// computes (A^B)%MOD
{
ll ans=1;
A=A%MOD;
while(B>0)
{
if(B&1) ans=(ans*A)%MOD;
B=B>>1;
A=(A*A)%MOD;
}
return ans;
}
int main()
{
cout<<"Enter number, power and MOD\n";
ll a,b,c;
cin>>a>>b>>c;
cout<<Modular_Exponentiation(a,b,c)<<"\n";
return 0;
}

0 comments on commit ac97dbe

Please sign in to comment.