Exponential Squaring ( Fast Modulo Multiplication ) | C # program to compute exponential value using ( 2 ^ k ) - ary method . ; prime modulo value ; for cases where exponent is not an even value ; Driver Code
using System ; class GFG { static long N = 1000000007L ; static long exponentiation ( long bas , long exp ) { long t = 1L ; while ( exp > 0 ) { if ( exp % 2 != 0 ) t = ( t * bas ) % N ; bas = ( bas * bas ) % N ; exp /= 2 ; } return t % N ; } public static void Main ( ) { long bas = 5 ; long exp = 100000 ; long modulo = exponentiation ( bas , exp ) ; Console . WriteLine ( modulo ) ; } }