Do these associate correctly? (Maybe better to write as `(r * n) % d` and `(n * n) % d` just to be clear?)