text: Find ( a ^ b ) % m where ' a ' is very large | C # program to find ( a ^ b ) mod m for a large ' a ' ; utility function to calculate a % m ; ( s [ i ] - '0' ) gives the digit value and form the number ; Returns find ( a ^ b ) % m ; Find a % m ; now multiply ans by b - 1 times and take mod with m ; Driver Code
code: using System ; class GFG { static int aModM ( string s , int mod ) { int number = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) { number = ( number * 10 ) ; int x = ( int ) ( s [ i ] - '0' ) ; number = number + x ; number %= mod ; } return number ; } static int ApowBmodM ( string a , int b , int m ) { int ans = aModM ( a , m ) ; int mul = ans ; for ( int i = 1 ; i < b ; i ++ ) ans = ( ans * mul ) % m ; return ans ; } public static void Main ( ) { string a = "987584345091051645734583954832576" ; int b = 3 , m = 11 ; Console . Write ( ApowBmodM ( a , b , m ) ) ; } }