Groups
Category
Modular arithmetic is about working with remainders, but programming languages often return negative remainders, so always normalize with (a % MOD + MOD) % MOD.
Integer overflow happens when a computed value exceeds the range of its type; in C++ this silently wraps for unsigned and is undefined for signed, so prevention is crucial.