Multiply large integers under large modulo | Returns ( a * b ) % mod ; Initialize result ; Update a if it is more than or equal to mod ; If b is odd , add a with result ; Here we assume that doing 2 * a doesn 't cause overflow ; b = ( b >> 1 ) ; b = b / 2 ; Driver Code
function moduloMultiplication ( a , b , mod ) { let res = 0 ; a = ( a % mod ) ; while ( b > 0 ) { if ( ( b & 1 ) > 0 ) { res = ( res + a ) % mod ; } a = ( 2 * a ) % mod ; } return res ; } let a = 426 ; let b = 964 ; let m = 235 ; document . write ( moduloMultiplication ( a , b , m ) ) ;