Modular Exponentiation

Untitled

Recursive: (a, b both in decimal. we are calculating a^b)

Untitled

Iterative: (a, b both in decimal. we are calculating a^b)

Untitled

Use mod & long long int.

Main Way of Thinking or Reasoning of this algo: (a in decimal, b in binary. we are calculating a^b)

Untitled

Its algo from DM book: see page 268

So someone can even save the values of base^(2^k) in an array and then use them accordingly.

<aside> 💡 I cannot connect between the main way and the practical way (recursive & iterative). I mean how they are doing the same thing?

</aside>