Fun with residue number systems (and some number theory) in Python