YoushouldhavereceivedcopiesoftheGNUGeneralPublicLicenseandthe GNULesserGeneralPublicLicensealongwiththeGNUMPLibrary.Ifnot,
see https://www.gnu.org/licenses/. */
#include"gmp-impl.h" #include"longlong.h"
/* Returns an approximation of the sqare root of x. *Itgives: *limb_apprsqrt(x)^2<=x<(limb_apprsqrt(x)+1)^2 *or *x<=limb_apprsqrt(x)^2<=x*9/8
*/ static mp_limb_t
limb_apprsqrt (mp_limb_t x)
{ int s;
staticint
mpz_oddjacobi_ui (mpz_t b, mp_limb_t a)
{
mp_limb_t b_rem; int result_bit1;
ASSERT (a & 1);
ASSERT (a > 1);
ASSERT (SIZ (b) > 0);
ASSERT ((*PTR (b) & 1) == 1);
result_bit1 = 0;
JACOBI_MOD_OR_MODEXACT_1_ODD (result_bit1, b_rem, PTR (b), SIZ (b), a); if (UNLIKELY (b_rem == 0)) return0; else return mpn_jacobi_base (b_rem, a, result_bit1);
}
/* Performs strong Lucas' test on x, with parameters suggested */ /* for the BPSW test. Qk and V are passed to recycle variables. */ /* Requires GCD (x,6) = 1.*/ int
mpz_stronglucas (mpz_srcptr x, mpz_ptr V, mpz_ptr Qk)
{
mp_bitcnt_t b0;
mpz_t n;
mp_limb_t D; /* The absolute value is stored. */
mp_limb_t g; long Q;
mpz_t T1, T2;
/* Test on the absolute value. */
mpz_roinit_n (n, PTR (x), ABSIZ (x));
/* n is odd, to possibly be a square, n % 8 = 1 is needed. */ if (((*PTR (n) & 6) == 0) && UNLIKELY (mpz_perfect_square_p (n))) return0; /* A square is composite. */
/* Check Ds up to square root (in case, n is prime)
or avoid overflows */ if (SIZ (n) == 1)
maxD = limb_apprsqrt (* PTR (n)); elseif (BITS_PER_ULONG >= GMP_NUMB_BITS && SIZ (n) == 2)
mpn_sqrtrem (&maxD, (mp_ptr) NULL, PTR (n), 2); else
maxD = GMP_NUMB_MAX;
maxD = MIN (maxD, ULONG_MAX);
/* Search a D such that (D/n) = -1 in the sequence 5,-7,9,-11,.. */ /* For those Ds we have (D/n) = (n/|D|) */ /* FIXME: Should we loop only on prime Ds? */ /* The only interesting composite D is 15, because 3 is not tested. */ for (;;)
{
jac = mpz_oddjacobi_ui (n, D); if (jac != 1) break; if (UNLIKELY (D >= maxD)) return1;
D += Ddiff;
Ddiff = D2 - Ddiff;
}
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 und die Messung sind noch experimentell.