/* mpz_remove -- divide out a factor and return its multiplicity.
Copyright 1998-2002, 2012 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
or
* the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
or both in parallel, as here.
The GNU MP Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received copies of the GNU General Public License and the GNU Lesser General Public License along with the GNU MP Library. If not,
see https://www.gnu.org/licenses/. */
#if WANT_ORIGINAL_DEST
mp_ptr dp;
dp = PTR (dest); #endif /* We could perhaps compute mpz_scan1(src,0)/mpz_scan1(f,0). It is an upper bound of the result we're seeking. We could also shift down the operands so that they become odd, to make intermediate values
smaller. */
mpz_init_set (fpow[0], f);
mpz_swap (dest, x);
p = 1; /* Divide by f, f^2 ... f^(2^k) until we get a remainder for f^(2^k). */ while (ABSIZ (dest) >= 2 * ABSIZ (fpow[p - 1]) - 1)
{
mpz_init (fpow[p]);
mpz_mul (fpow[p], fpow[p - 1], fpow[p - 1]);
mpz_tdiv_qr (x, rem, dest, fpow[p]); if (SIZ (rem) != 0) {
mpz_clear (fpow[p]); break;
}
mpz_swap (dest, x);
p++;
}
pwr = ((mp_bitcnt_t)1 << p) - 1;
/* Divide by f^(2^(k-1)), f^(2^(k-2)), ..., f for all divisors that give
a zero remainder. */ while (--p >= 0)
{
mpz_tdiv_qr (x, rem, dest, fpow[p]); if (SIZ (rem) == 0)
{
pwr += (mp_bitcnt_t)1 << p;
mpz_swap (dest, x);
}
mpz_clear (fpow[p]);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.