Compute where can be up to .
For example, .
You'll use exponentiation by squaring, but take the modulo after every multiplication to keep intermediate results small.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Fast exponentiation with mod
Compute where can be up to .
For example, .
You'll use exponentiation by squaring, but take the modulo after every multiplication to keep intermediate results small.