http://benji3up2kxewkqfcq7buxk2xd6zwy3zggnurkrm3l4cvwy2iipvyyad.onion/mirrors/gmpdoc/Efficiency.html
However when testing divisibility by several small integers, it’s best to take
a remainder modulo their product, to save multi-precision operations. For
instance to test whether a number is divisible by 23, 29 or 31 take a
remainder modulo 23*29*31 = 20677 and then test that. The division functions like mpz_tdiv_q_ui which give a quotient as well
as a remainder are generally a little slower than the remainder-only functions
like mpz_tdiv_ui .