From 365e9a823aef4b259de1cfece23ef383f6b7fc18 Mon Sep 17 00:00:00 2001 From: Shri Prakash Bajpai <68155959+Shri2206@users.noreply.github.com> Date: Thu, 22 Oct 2020 01:05:42 +0530 Subject: [PATCH] Update modular_exponentiation.cpp --- math/modular_exponentiation.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/math/modular_exponentiation.cpp b/math/modular_exponentiation.cpp index 1ccd67434..6f133b700 100644 --- a/math/modular_exponentiation.cpp +++ b/math/modular_exponentiation.cpp @@ -30,9 +30,10 @@ namespace math { * @param c integer modulo * @return a raised to power b modulo c */ -int power(int a, unsigned int b, int c) + +uint64_t power(uint64_t a, uint64_t b, uint64_t c) { - int ans = 1; /// Initialize the answer to be returned + uint64_t ans = 1; /// Initialize the answer to be returned a = a % c; /// Update a if it is more than or /// equal to c @@ -41,7 +42,7 @@ int power(int a, unsigned int b, int c) { return 0; /// In case a is divisible by c; } - + while (b > 0) { /// If b is odd, multiply a with answer @@ -49,12 +50,12 @@ int power(int a, unsigned int b, int c) { ans = (ans*a) % c; } - + /// b must be even now b = b>>1; // b = b/2 a = (a*a) % c; } - + return ans; } } // namespace math @@ -66,10 +67,10 @@ int power(int a, unsigned int b, int c) int main() { /// Give two numbers num1, num2 and modulo m - int num1 = 2; - int num2 = 5; - int m = 13; - + uint64_t num1 = 2; + uint64_t num2 = 5; + uint64_t m = 13; + std::cout << "The value of "<