Topics
Why ans modulo often asked in competitive programming?
- It’s prime and primes have least “collision”
- Chances for 2 numbers to have same value after mod, when is prime is lower than when is non-prime
- It’s the first prime after
- Sum of 2 nums and will fit in
int
under moduloa%m + b%m
fits underint
datatype
- Product of and fits in
long long
under modulo(a%m) * (b%m)
fits underlong long
datatype
- Taking modulo is a nice way to prevent overflows