Some number theory related utility code.