diff --git a/Problem Set 1 Arithmetic/1.6 Find a^b.py b/Problem Set 1 Arithmetic/1.6 Find a^b.py index 293ba63..833f290 100644 --- a/Problem Set 1 Arithmetic/1.6 Find a^b.py +++ b/Problem Set 1 Arithmetic/1.6 Find a^b.py @@ -9,9 +9,17 @@ ## Syntax: pow(base,exponent) # exp = pow(a,b) -## Return Modulo for Exponent with Built-in Function -## Syntax: pow(base,exponent, modulo) -# exp = pow(a,b,2) +#function for modular exponentiation i.e., (b^n)%m +## usage pow(b,n,m) +def pow(b,n,m): + r=1 + while n: + if n%1: + r=(r*b)%m + b=(b*b)%m + n>>=1 + return r + ## Using Math Library # import math