# query: nearest integer divide

**Torbjorn Granlund
**
tege@swox.com

*24 Mar 2003 11:32:42 +0100*

keith.briggs@bt.com writes:
1. mpz_ui_pow_ui(temp,2,p-1);
mpz_add(y,x,temp);
mpz_tdiv_q_2exp(y,y,p);
It would save a lot of time to perform that mpz_tdiv_q_2exp with
mpz_mul_2exp instead. It would vring time down from O(M(2^p)) to
O(2^p), where M(n) is the time for multiplying two n-bit numbers.
(If your x is computed for the sole purpose of getting this
nearest integer, you might be able to save a great amount of time
by not computing the full precision of x, and instead just some
upper part of it.)
--
Torbjörn