human
Write me a code to how to avoid overflow in modular multiplication given the following:
How to avoid overflow in modular multiplication ? | To compute ( a * b ) % mod.
res = 0.
Initialize result.
If b is odd , add ' a ' to result.
Multiply ' a ' with 2.
Divide b by 2.
Return result.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to how to avoid overflow in modular multiplication .
 def mulmod ( a , b , mod ) :
	a = a % mod ;
	while ( b > 0 ) :
		if ( b % 2 == 1 ) :
			res = ( res + a ) % mod ;
		a = ( a * 2 ) % mod ;
		b //= 2 ;
	return res % mod ;
a = 9223372036854775807 ;
b = 9223372036854775807 ;
print ( mulmod ( a , b , 100000000000 ) ) ;