How to calculate the modulus of the form (a * b)% c?
I want to calculate the multiplication module of two int numbers, where they are almost at the overflow stage ...
here c is also int
(a * b) % c == ((a % c) * (b % c)) % c
How about ((a % c) * (b % c)) % c? Depending on your architecture, this may be faster or slower than casting to a larger type.
((a % c) * (b % c)) % c
a c long long, .
a
c
long long
((long long)a * (long long)b) % c