@@ -0,0 +1,1217 @@
+%22%22%22%0A* Binary Exponentiation%0A* This is a method to find a%5Eb in a time complexity of O(log b)%0A* This is one of the most commonly used methods of finding powers.%0A* Also useful in cases where solution to (a%5Eb)%25c is required,%0A* where a,b,c can be numbers over the computers calculation limits.%0A* Done using iteration, can also be done using recursion%0A%0A* @author chinmoy159%0A* @version 1.0 dated 10/08/2017%0A%22%22%22%0A%0A%0Adef b_expo(a, b):%0A    res = 1%0A    while b %3E 0:%0A        if b&1:%0A            res *= a%0A%0A        a *= a%0A        b %3E%3E= 1%0A%0A    return res%0A%0A%0Adef b_expo(a, b, c):%0A    res = 1%0A    while b %3E 0:%0A        if b&1:%0A            res = ((res%25c) * (a%25c)) %25 c%0A%0A        a *= a%0A        b %3E%3E= 1%0A%0A    return res%0A%0A%22%22%22%0A* Wondering how this method works !%0A* It's pretty simple.%0A* Let's say you need to calculate a %5E b%0A* RULE 1 : a %5E b = (a*a) %5E (b/2) ---- example : 4 %5E 4 = (4*4) %5E (4/2) = 16 %5E 2%0A* RULE 2 : IF b is ODD, then ---- a %5E b = a * (a %5E (b - 1)) :: where (b - 1) is even.%0A* Once b is even, repeat the process to get a %5E b%0A* Repeat the process till b = 1 OR b = 0, because a%5E1 = a AND a%5E0 = 1%0A*%0A* As far as the modulo is concerned,%0A* the fact : (a*b) %25 c = ((a%25c) * (b%25c)) %25 c%0A* Now apply RULE 1 OR 2 whichever is required.%0A%22%22%22%0A

Create binary_exponentiation.py