Work Modulo a Prime
Add, multiply, and stay inside the mod.
Why Take the Modulo
Contest answers can grow huge, way past any integer type elsewhere. So problems ask for the result modulo a big prime to keep numbers small. 🔢
Meet the Famous Mod
The prime you will see most is 1000000007, often written 1e9+7. It is just big enough to dodge collisions and small enough to fit in 64 bits.
MOD = 1000000007