From 8761b26f01e0826b6f1f931ebf5aa71b357e2143 Mon Sep 17 00:00:00 2001 From: abhstract Date: Tue, 27 Oct 2020 11:25:01 +0530 Subject: [PATCH 1/2] Modular exponentiation in c++ wrt to CSES problem Statement --- C++/modular_exponentiation.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 C++/modular_exponentiation.cpp diff --git a/C++/modular_exponentiation.cpp b/C++/modular_exponentiation.cpp new file mode 100644 index 0000000..fe09268 --- /dev/null +++ b/C++/modular_exponentiation.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; +#define ll long long int +ll mod=1e9+7; +ll solve(ll a,ll b) +{ + + if(b==0) + return 1; + a=a%mod; + ll res=(solve(a,b/2)%mod); + res=(res*res)%mod; + if(b%2!=0) + res*=a; + return res%mod; +} +int main() +{ + int t; + cin>>t; + //cout<>a>>b; + cout< Date: Tue, 27 Oct 2020 11:30:22 +0530 Subject: [PATCH 2/2] Update modular_exponentiation.cpp --- C++/modular_exponentiation.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/C++/modular_exponentiation.cpp b/C++/modular_exponentiation.cpp index fe09268..bf4a78c 100644 --- a/C++/modular_exponentiation.cpp +++ b/C++/modular_exponentiation.cpp @@ -4,7 +4,6 @@ using namespace std; ll mod=1e9+7; ll solve(ll a,ll b) { - if(b==0) return 1; a=a%mod;