>then associativity of integer multiplication, then some (probably builtin) rule that `n%n` is always 0.
Is this quite right? It's not true in general that (a * b) % c = a * (b % c). E.g. it's not true for 2,3,4. The relevant generalization is that (a * b) % b = 0, which has nothing to do with associativity.