Math Fundamentals18 sections · 814 units
Open in Course

Avoiding Common Mistakes

Pitfalls to watch for

Watch out for these errors:

1.1. Confusing // and  mod \bmod. Division gives the quotient, modulo gives the remainder. Both are needed for different purposes.

2.2. Forgetting parentheses with mixed operations. a+b mod ca + b \bmod c is not the same as (a+b) mod c(a + b) \bmod c.

3.3. Ignoring negative numbers. Modulo behavior with negatives varies by language. Use (a mod m+m) mod m(a \bmod m + m) \bmod m for safety.

4.4. Not applying modulo in intermediate steps. Large multiplications overflow if you don't reduce before the next operation.