How to avoid overflow in modular multiplication ? | A Simple solution that causes overflow when value of ( a % mod ) * ( b % mod ) becomes more than maximum value of long int
static long multiply ( long a , long b , long mod ) { return ( ( a % mod ) * ( b % mod ) ) % mod ; }