text: Find ( a ^ b ) % m where ' a ' is very large | 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: function aModM ( s , mod ) { let number = 0 ; for ( let i = 0 ; i < s . length ; i ++ ) { number = ( number * 10 ) ; let x = ( s [ i ] - ' ' ) ; number = number + x ; number %= mod ; } return number ; } function ApowBmodM ( a , b , m ) { let ans = aModM ( a , m ) ; let mul = ans ; for ( let i = 1 ; i < b ; i ++ ) ans = ( ans * mul ) % m ; return ans ; } let a = " " ; let b = 3 , m = 11 ; document . write ( ApowBmodM ( a , b , m ) ) ;