number theory algorithms