From ac97dbec9daf2157746190b9fc0295e6214b6e96 Mon Sep 17 00:00:00 2001 From: Ngo Minh Phuong <33479324+PPbra@users.noreply.github.com> Date: Mon, 8 Oct 2018 18:14:36 +0700 Subject: [PATCH] Create ppbra.cpp --- cpp/algorithms/ppbra.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 cpp/algorithms/ppbra.cpp diff --git a/cpp/algorithms/ppbra.cpp b/cpp/algorithms/ppbra.cpp new file mode 100644 index 000000000..b83e507e8 --- /dev/null +++ b/cpp/algorithms/ppbra.cpp @@ -0,0 +1,23 @@ +#include +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<