Initialize .
For each digit in (left to right): .
Use fast exponentiation for and .
Critical: Always take mod after each multiplication to prevent overflow.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Digit by digit computation
Initialize .
For each digit in (left to right): .
Use fast exponentiation for and .
Critical: Always take mod after each multiplication to prevent overflow.