fix off-by-one error
changing the argument order of `mulmod` improves performance slightly