Let a, b, and c be long long (int64) numbers, how to calculate (a*b)%c? The problem here is that you can't multiply (a%c)*(b%c) because it won't fit on an int64 variable. So, what can it be done?
Just in case it's helpful, I'm jusing C++.
Let a, b, and c be long long (int64) numbers, how to calculate (a*b)%c? The problem here is that you can't multiply (a%c)*(b%c) because it won't fit on an int64 variable. So, what can it be done?
Just in case it's helpful, I'm jusing C++.
You could use an arbitrary precision library such as gmp to ensure that you'll never overflow your numerical type.
or you ensure that your multiplication will not overflow your type. Without knowing more about your input, I can't really speculate on good ways to do that.
Or this question is very applicable to your task.