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 modulo
    • a%m + b%m fits under int datatype
  • Product of and fits in long long under modulo
    • (a%m) * (b%m) fits under long long datatype
  • Taking modulo is a nice way to prevent overflows