Branch Coverage

primality.c
Criterion Covered Total %
branch 680 1022 66.5


line true false branch
24 13344 0 if (m <= 0 || (m%2) == 0) return 0;
0 13344 if (m <= 0 || (m%2) == 0) return 0;
25 196 13148 if (in < 0 && (m%4) == 3) j = -j;
80 116 if (in < 0 && (m%4) == 3) j = -j;
26 31128 13344 while (n != 0) {
27 26612 31128 while ((n % 2) == 0) {
29 19998 6614 if ( (m % 8) == 3 || (m % 8) == 5 ) j = -j;
10662 9336 if ( (m % 8) == 3 || (m % 8) == 5 ) j = -j;
32 13891 17237 if ( (n % 4) == 3 && (m % 4) == 3 ) j = -j;
2634 11257 if ( (n % 4) == 3 && (m % 4) == 3 ) j = -j;
35 13326 18 return (m == 1) ? j : 0;
44 0 13060 if (j == 0) return 0;
45 5894 7166 if (j == -1) break;
46 13 7153 if (P == (3+20*increment) && is_perfect_square(n)) return 0;
0 13 if (P == (3+20*increment) && is_perfect_square(n)) return 0;
48 0 7166 if (P > 65535)
51 0 5894 if (P >= n) P %= n; /* Never happens with increment < 4 */
58 0 86 if (n < 4) return (n == 2 || n == 3);
0 0 if (n < 4) return (n == 2 || n == 3);
0 0 if (n < 4) return (n == 2 || n == 3);
59 2 84 if (!(n&1) && !(a&1)) return 0;
0 2 if (!(n&1) && !(a&1)) return 0;
60 0 86 if (a < 2) croak("Base %"UVuf" is invalid", a);
61 0 86 if (a >= n) {
63 0 0 if (a <= 1) return (a == 1);
64 0 0 if (a == n-1) return !(a & 1);
68 84 2 if (n & 1) { /* The Montgomery code only works for odd n */
70 41 43 const uint64_t monta = (a == 2) ? mont_get2(n) : mont_geta(a, n);
80 0 109 if (n < 5) return (n == 2 || n == 3);
0 0 if (n < 5) return (n == 2 || n == 3);
0 0 if (n < 5) return (n == 2 || n == 3);
81 0 109 if (!(n&1)) return 0;
82 0 109 if (a < 2) croak("Base %"UVuf" is invalid", a);
83 73 36 if (a > 2) {
84 1 72 if (a >= n) {
86 0 1 if (a <= 1) return (a == 1);
87 1 0 if (a == n-1) return !(a & 1);
89 0 72 if ((n % a) == 0) return 0;
96 23 85 if (ap != mont1 && ap != n-mont1) return 0;
0 23 if (ap != mont1 && ap != n-mont1) return 0;
97 36 72 if (a == 2) {
99 8 28 return (nmod8 == 1 || nmod8 == 7) ? (ap == mont1) : (ap == n-mont1);
3 5 return (nmod8 == 1 || nmod8 == 7) ? (ap == mont1) : (ap == n-mont1);
101 54 18 return (kronecker_uu(a,n) >= 0) ? (ap == mont1) : (ap == n-mont1);
124 0 1195 if (n < 5) return (n == 2 || n == 3);
0 0 if (n < 5) return (n == 2 || n == 3);
0 0 if (n < 5) return (n == 2 || n == 3);
125 0 1195 if (!(n&1)) return 0;
130 314 881 ap = mont_powmod(mont2, (n-1) >> (1 + (nmod8 == 1)), n);
131 425 770 if (ap == mont1) return (nmod8 == 1 || nmod8 == 7);
273 152 if (ap == mont1) return (nmod8 == 1 || nmod8 == 7);
273 0 if (ap == mont1) return (nmod8 == 1 || nmod8 == 7);
132 761 9 if (ap == n-mont1) return (nmod8 == 1 || nmod8 == 3 || nmod8 == 5);
602 159 if (ap == n-mont1) return (nmod8 == 1 || nmod8 == 3 || nmod8 == 5);
301 301 if (ap == n-mont1) return (nmod8 == 1 || nmod8 == 3 || nmod8 == 5);
301 0 if (ap == n-mont1) return (nmod8 == 1 || nmod8 == 3 || nmod8 == 5);
149 0 105429 MPUassert(n > 3, "MR called with n <= 3");
150 1 105428 if ((n & 1) == 0) return 0;
156 209050 105428 while (!(u&1)) { t++; u >>= 1; }
157 109293 42692 for (j = 0; j < nbases; j++) {
159 2 109291 if (a < 2) croak("Base %"UVuf" is invalid", (UV)a);
160 5425 103866 if (a >= n) {
162 5419 6 if (a == 0 || (a == n-1 && a&1)) return 0;
2 5417 if (a == 0 || (a == n-1 && a&1)) return 0;
0 2 if (a == 0 || (a == n-1 && a&1)) return 0;
165 109274 11 if (a == 1 || a == n-1 || !ma) continue;
109264 10 if (a == 1 || a == n-1 || !ma) continue;
0 109264 if (a == 1 || a == n-1 || !ma) continue;
167 89291 19973 if (md != mont1 && md != n-mont1) {
76596 12695 if (md != mont1 && md != n-mont1) {
168 92635 62626 for (i=1; i
169 0 92635 md = mont_sqrmod(md, n);
170 102 92533 if (md == mont1) return 0;
171 13868 78665 if (md == n-mont1) break;
173 62626 13868 if (i == t)
213 0 8265 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
214 8265 0 if ((n % 2) == 0 || n == UV_MAX) return 0;
0 8265 if ((n % 2) == 0 || n == UV_MAX) return 0;
228 16655 8265 while (!(u&1)) { t++; u >>= 1; }
230 6910 1355 if (md != mont1 && md != n-mont1) {
5449 1461 if (md != mont1 && md != n-mont1) {
231 6446 3577 for (i=1; i
232 104 6342 md = mont_sqrmod(md, n);
233 0 6446 if (md == mont1) return 0;
234 1872 4574 if (md == n-mont1) break;
236 3577 1872 if (i == t)
241 0 4688 if (P == 0) return 0;
245 9568 4688 while ( (d & 1) == 0 ) { s++; d >>= 1; }
250 72 4616 W = submod( mont_mulmod( montP, montP, n), mont2, n);
252 220626 4688 { UV v = d; b = 1; while (v >>= 1) b++; }
253 220626 4688 while (b-- > 1) {
254 4383 216243 UV T = submod( mont_mulmod(V, W, n), montP, n);
255 117730 102896 if ( (d >> (b-1)) & UVCONST(1) ) {
257 2283 115447 W = submod( mont_mulmod(W, W, n), mont2, n);
260 2100 100796 V = submod( mont_mulmod(V, V, n), mont2, n);
265 4265 423 if (V == mont2 || V == (n-mont2))
2190 2075 if (V == mont2 || V == (n-mont2))
267 4530 65 while (s-- > 1) {
268 2010 2520 if (V == 0)
270 49 2471 V = submod( mont_mulmod(V, V, n), mont2, n);
271 0 2520 if (V == mont2)
288 0 1 { UV v = k; while (!(v & 1)) { v >>= 1; s++; } }
289 23 1 { UV v = k; while (v >>= 1) m++; }
291 1 0 if (Pmod == 1 && Qmod == (n-1)) {
1 0 if (Pmod == 1 && Qmod == (n-1)) {
293 23 1 for (j = m; j > s; j--) {
295 8 15 Ql = (Sl==1) ? 1 : n-1;
296 8 15 if ( (k >> j) & UVCONST(1) ) {
300 6 2 Vh = submod(sqrmod(Vh, n), (Sh==1) ? 2 : n-2, n);
305 6 9 Vl = submod(sqrmod(Vl, n), (Sl==1) ? 2 : n-2, n);
309 0 1 Ql = (Sl==1) ? 1 : n-1;
312 0 1 for (j = 0; j < s; j++) {
314 0 0 Vl = submod(sqrmod(Vl, n), (j>0) ? 2 : n-2, n);
318 1 0 *Qkret = (s>0)?1:n-1;
322 0 0 for (j = m; j > s; j--) {
324 0 0 if ( (k >> j) & UVCONST(1) ) {
341 0 0 for (j = 0; j < s; j++) {
356 0 26319 MPUassert(n > 1, "lucas_sequence: modulus n must be > 1");
357 25 26294 if (k == 0) {
364 26139 155 Qmod = (Q < 0) ? (UV) (Q + (IV)(((-Q/n)+1)*n)) : (UV)Q % n;
365 0 26294 Pmod = (P < 0) ? (UV) (P + (IV)(((-P/n)+1)*n)) : (UV)P % n;
367 13 26281 if (Dmod == 0) {
374 1 26280 if ((n % 2) == 0) {
381 365056 26280 { UV v = k; b = 0; while (v >>= 1) b++; }
383 53 26227 if (Q == 1) {
384 133 53 while (b--) {
387 51 82 if ( (k >> b) & UVCONST(1) ) {
390 2 49 if (U & 1) { U = (n>>1) + (U>>1) + 1; } else { U >>= 1; }
392 4 47 if (V & 1) { V = (n>>1) + (V>>1) + 1; } else { V >>= 1; }
395 25973 254 } else if (P == 1 && Q == -1) {
25944 29 } else if (P == 1 && Q == -1) {
399 363747 25944 while (b--) {
401 169766 193981 if (sign == 1) V = mulsubmod(V, V, 2, n);
404 168054 195693 if ( (k >> b) & UVCONST(1) ) {
407 62316 105738 if (U & 1) { U = (n>>1) + (U>>1) + 1; } else { U >>= 1; }
409 63745 104309 if (V & 1) { V = (n>>1) + (V>>1) + 1; } else { V >>= 1; }
413 25927 17 if (sign == 1) Qk = 1;
415 1176 283 while (b--) {
419 536 640 if ( (k >> b) & UVCONST(1) ) {
422 124 412 if (U & 1) { U = (n>>1) + (U>>1) + 1; } else { U >>= 1; }
424 167 369 if (V & 1) { V = (n>>1) + (V>>1) + 1; } else { V >>= 1; }
440 0 199 if (U == 0) return 0;
441 14 185 if (k == 0) { *U = 0; return 1; }
445 147 185 { UV v = k; while (!(v & 1)) { v >>= 1; s++; } }
446 403 185 { UV v = k; while (v >>= 1) n++; }
448 256 185 for (j = n; j > s; j--) {
449 256 0 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
256 0 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
256 0 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
256 0 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
0 256 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
451 175 81 if ( (k >> j) & UVCONST(1) ) {
463 185 0 if (OVERHALF(Ql) || OVERHALF(Qh)) return 0;
0 185 if (OVERHALF(Ql) || OVERHALF(Qh)) return 0;
466 185 0 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
185 0 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
185 0 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
185 0 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
0 185 if (OVERHALF(Uh) || OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
470 147 185 for (j = 0; j < s; j++) {
471 147 0 if (OVERHALF(Uh) || OVERHALF(Vl) || OVERHALF(Ql)) return 0;
147 0 if (OVERHALF(Uh) || OVERHALF(Vl) || OVERHALF(Ql)) return 0;
0 147 if (OVERHALF(Uh) || OVERHALF(Vl) || OVERHALF(Ql)) return 0;
484 0 152 if (V == 0) return 0;
485 11 141 if (k == 0) { *V = 2; return 1; }
489 110 141 { UV v = k; while (!(v & 1)) { v >>= 1; s++; } }
490 304 141 { UV v = k; while (v >>= 1) n++; }
492 194 141 for (j = n; j > s; j--) {
493 194 0 if (OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
194 0 if (OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
194 0 if (OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
0 194 if (OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
495 130 64 if ( (k >> j) & UVCONST(1) ) {
505 141 0 if (OVERHALF(Ql) || OVERHALF(Qh)) return 0;
0 141 if (OVERHALF(Ql) || OVERHALF(Qh)) return 0;
508 141 0 if (OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
141 0 if (OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
141 0 if (OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
0 141 if (OVERHALF(Vh) || OVERHALF(Vl) || OVERHALF(Ql) || OVERHALF(Qh)) return 0;
511 110 141 for (j = 0; j < s; j++) {
512 110 0 if (OVERHALF(Vl) || OVERHALF(Ql)) return 0;
0 110 if (OVERHALF(Vl) || OVERHALF(Ql)) return 0;
534 1 70 if (n < 5) return (n == 2 || n == 3);
0 1 if (n < 5) return (n == 2 || n == 3);
0 0 if (n < 5) return (n == 2 || n == 3);
535 65 5 if ((n % 2) == 0 || n == UV_MAX) return 0;
0 65 if ((n % 2) == 0 || n == UV_MAX) return 0;
537 43 22 if (strength < 3) {
544 44 64 if (j != 1 && Du != n) break;
43 1 if (j != 1 && Du != n) break;
545 0 65 if (Du == 21 && is_perfect_square(n)) return 0;
0 0 if (Du == 21 && is_perfect_square(n)) return 0;
549 1 42 if (j != -1) return 0;
552 0 42 if (strength == 2 && Q == -1) P=Q=D=5; /* Method A* */
0 0 if (strength == 2 && Q == -1) P=Q=D=5; /* Method A* */
554 22 20 Qk = (Q >= 0) ? Q % n : n-(((UV)(-Q)) % n);
555 0 42 if (gcd_ui(Qk,n) != 1) return 0;
558 0 22 if (P == 0) return 0;
562 0 64 MPUassert( D == (P*P - 4*Q) , "is_lucas_pseudoprime: incorrect DPQ");
573 44 20 if (strength > 0)
574 98 44 while ( (d & 1) == 0 ) { s++; d >>= 1; }
581 22 42 : (P >= 0) ? mont_geta(P, n)
582 22 0 : n - mont_geta(-P, n);
584 42 22 : (Q >= 0) ? mont_geta(Q, n)
585 22 20 : n - mont_geta(-Q, n);
587 42 22 : n - mont_geta(-D, n);
589 935 64 { UV v = d; b = 0; while (v >>= 1) b++; }
595 42 22 if (Q == 1 || Q == -1) { /* Faster code for |Q|=1, also opt for P=1 */
16 26 if (Q == 1 || Q == -1) { /* Faster code for |Q|=1, also opt for P=1 */
597 572 38 while (b--) {
598 0 572 U = mont_mulmod(U, V, n);
599 471 101 if (sign == 1) V = submod( mont_sqrmod(V,n), mont2, n);
0 471 if (sign == 1) V = submod( mont_sqrmod(V,n), mont2, n);
600 0 101 else V = addmod( mont_sqrmod(V,n), mont2, n);
602 238 334 if ( (d >> b) & UVCONST(1) ) {
603 0 238 UV t2 = mont_mulmod(U, montD, n);
604 92 146 if (P == 1) {
608 0 146 U = addmod( mont_mulmod(U, montP, n), V, n);
609 0 146 V = addmod( mont_mulmod(V, montP, n), t2, n);
611 105 133 if (U & 1) { U = (n>>1) + (U>>1) + 1; } else { U >>= 1; }
612 126 112 if (V & 1) { V = (n>>1) + (V>>1) + 1; } else { V >>= 1; }
616 7 31 Qk = (sign == 1) ? mont1 : n-mont1;
619 363 26 while (b--) {
620 0 363 U = mont_mulmod(U, V, n);
621 0 363 V = submod( mont_sqrmod(V,n), addmod(Qk,Qk,n), n);
622 0 363 Qk = mont_sqrmod(Qk,n);
623 186 177 if ( (d >> b) & UVCONST(1) ) {
624 0 186 UV t2 = mont_mulmod(U, montD, n);
625 0 186 U = addmod( mont_mulmod(U, montP, n), V, n);
626 84 102 if (U & 1) { U = (n>>1) + (U>>1) + 1; } else { U >>= 1; }
627 0 186 V = addmod( mont_mulmod(V, montP, n), t2, n);
628 102 84 if (V & 1) { V = (n>>1) + (V>>1) + 1; } else { V >>= 1; }
629 0 186 Qk = mont_mulmod(Qk, montQ, n);
634 20 44 if (strength == 0) {
635 20 0 if (U == 0)
637 22 22 } else if (strength == 1) {
638 8 14 if (U == 0)
640 36 3 while (s--) {
641 11 25 if (V == 0)
643 22 3 if (s) {
644 0 22 V = submod( mont_sqrmod(V,n), addmod(Qk,Qk,n), n);
645 0 22 Qk = mont_sqrmod(Qk,n);
648 0 22 } else if (strength == 2) {
651 0 0 if (U == 0)
653 0 0 while (s--) {
654 0 0 if (V == 0)
657 0 0 V = submod( mont_sqrmod(V,n), addmod(Qk,Qk,n), n);
658 0 0 Qk = mont_sqrmod(Qk,n);
660 0 0 if (!is_slpsp) return 0; /* slpsp */
661 0 0 if (V != addmod(montQ,montQ,n)) return 0; /* V_{n+1} != 2Q mod n */
663 0 0 Qj = (qjacobi == 0) ? 0 : (qjacobi == 1) ? montQ : n-montQ;
0 0 Qj = (qjacobi == 0) ? 0 : (qjacobi == 1) ? montQ : n-montQ;
664 0 0 if (Ql != Qj) return 0; /* n is epsp base Q */
667 14 8 if ( U == 0 && (V == mont2 || V == (n-mont2)) )
11 3 if ( U == 0 && (V == mont2 || V == (n-mont2)) )
11 0 if ( U == 0 && (V == mont2 || V == (n-mont2)) )
670 20 0 while (s--) {
671 8 12 if (V == 0)
673 12 0 if (s)
674 0 12 V = submod( mont_sqrmod(V,n), mont2, n);
750 0 1184 if (n < 13) return (n == 2 || n == 3 || n == 5 || n == 7 || n == 11);
0 0 if (n < 13) return (n == 2 || n == 3 || n == 5 || n == 7 || n == 11);
0 0 if (n < 13) return (n == 2 || n == 3 || n == 5 || n == 7 || n == 11);
0 0 if (n < 13) return (n == 2 || n == 3 || n == 5 || n == 7 || n == 11);
0 0 if (n < 13) return (n == 2 || n == 3 || n == 5 || n == 7 || n == 11);
0 0 if (n < 13) return (n == 2 || n == 3 || n == 5 || n == 7 || n == 11);
751 1184 0 if ((n % 2) == 0 || n == UV_MAX) return 0;
0 1184 if ((n % 2) == 0 || n == UV_MAX) return 0;
752 1184 0 if (increment < 1 || increment > 256)
0 1184 if (increment < 1 || increment > 256)
756 0 1184 if ( (increment >= 16 && n <= 331) || (increment > 148 && n <= 631) )
0 0 if ( (increment >= 16 && n <= 331) || (increment > 148 && n <= 631) )
0 1184 if ( (increment >= 16 && n <= 331) || (increment > 148 && n <= 631) )
0 0 if ( (increment >= 16 && n <= 331) || (increment > 148 && n <= 631) )
760 0 1184 if (P == 0) return 0;
764 2351 1184 while ( (d & 1) == 0 ) { s++; d >>= 1; }
765 18226 1184 { UV v = d; b = 0; while (v >>= 1) b++; }
772 0 1184 W = submod( mont_mulmod( montP, montP, n), mont2, n);
774 18226 1184 while (b--) {
775 0 18226 UV T = submod( mont_mulmod(V, W, n), montP, n);
776 9373 8853 if ( (d >> b) & UVCONST(1) ) {
778 0 9373 W = submod( mont_mulmod(W, W, n), mont2, n);
781 0 8853 V = submod( mont_mulmod(V, V, n), mont2, n);
785 1052 132 if (V == mont2 || V == (n-mont2))
552 500 if (V == mont2 || V == (n-mont2))
788 1077 0 while (s--) {
789 500 577 if (V == 0)
791 577 0 if (s)
792 0 577 V = submod( mont_mulmod(V, V, n), mont2, n);
864 0 20 if (n <= 1) return;
867 18 2 if ( (n&1) ) {
876 605 20 { UV v = n; b = 1; while (v >>= 1) b++; }
878 605 20 while (b-- > 1) {
881 558 47 if (n&1) {
882 0 558 T[0] = submod(submod(mont_sqrmod(S[0],n), S[5],n), S[5],n);
883 0 558 T[1] = submod(submod(mont_sqrmod(S[1],n), S[4],n), S[4],n);
884 0 558 T[2] = submod(submod(mont_sqrmod(S[2],n), S[3],n), S[3],n);
885 0 558 T[3] = submod(submod(mont_sqrmod(S[3],n), S[2],n), S[2],n);
886 0 558 T[4] = submod(submod(mont_sqrmod(S[4],n), S[1],n), S[1],n);
887 0 558 T[5] = submod(submod(mont_sqrmod(S[5],n), S[0],n), S[0],n);
902 281 324 if ( (n >> (b-1)) & 1U ) {
911 18 2 if (n&1) { /* Recover result from Montgomery form */
912 108 18 for (i = 0; i < 6; i++)
913 0 108 S[i] = mont_recover(S[i],n);
923 0 20 if (n < 3) return (n >= 2);
924 2 18 if (!(n&1) && restricted > 2) return 0; /* Odds only for restrict > 2 */
0 2 if (!(n&1) && restricted > 2) return 0; /* Odds only for restrict > 2 */
929 2 18 if (!(n32&1) && !(( 22 >> (n32% 7)) & 1)) return 0;
0 2 if (!(n32&1) && !(( 22 >> (n32% 7)) & 1)) return 0;
930 0 20 if (!(n32%3) && !(( 523 >> (n32%13)) & 1)) return 0;
0 0 if (!(n32%3) && !(( 523 >> (n32%13)) & 1)) return 0;
931 2 18 if (!(n32%5) && !((65890 >> (n32%24)) & 1)) return 0;
0 2 if (!(n32%5) && !((65890 >> (n32%24)) & 1)) return 0;
932 0 20 if (!(n32%4) && !(( 514 >> (n32%14)) & 1)) return 0;
0 0 if (!(n32%4) && !(( 514 >> (n32%14)) & 1)) return 0;
934 300 20 for (i = 4; i < NPERRINDIV; i++) {
935 12 288 if ((n % _perrindata[i].div) == 0) {
938 0 12 if (!((mask[mod/32] >> (mod%32)) & 1))
946 0 20 if (S[4] != 0) return 0; /* P(n) = 0 mod n */
947 15 5 if (restricted == 0) return 1;
949 1 4 if (S[1] != n-1) return 0; /* P(-n) = -1 mod n */
950 1 3 if (restricted == 1) return 1;
966 1 2 if (jacobi == -1) { /* Q-type */
971 1 0 if (S[0] == A && S[2] == B && S[3] == B && S[5] == C &&
1 0 if (S[0] == A && S[2] == B && S[3] == B && S[5] == C &&
1 0 if (S[0] == A && S[2] == B && S[3] == B && S[5] == C &&
0 1 if (S[0] == A && S[2] == B && S[3] == B && S[5] == C &&
0 0 if (S[0] == A && S[2] == B && S[3] == B && S[5] == C &&
972 0 0 B != 3 && submod(mulmod(B2,B,n),B,n) == 1) {
973 0 0 MPUverbose(2, "%"UVuf" Q-Type %"UVuf" -1 %"UVuf" %"UVuf" 0 %"UVuf"\n", n, A, B, B, C);
979 2 0 if (jacobi == 0 && n != 23 && restricted > 2) {
2 0 if (jacobi == 0 && n != 23 && restricted > 2) {
1 1 if (jacobi == 0 && n != 23 && restricted > 2) {
980 0 1 MPUverbose(2, "%"UVuf" Jacobi %d\n",n,jacobi);
984 1 0 if (S[0] == 1 && S[2] == 3 && S[3] == 3 && S[5] == 2) {
1 0 if (S[0] == 1 && S[2] == 3 && S[3] == 3 && S[5] == 2) {
1 0 if (S[0] == 1 && S[2] == 3 && S[3] == 3 && S[5] == 2) {
1 0 if (S[0] == 1 && S[2] == 3 && S[3] == 3 && S[5] == 2) {
985 0 1 MPUverbose(2, "%"UVuf" S-Type 1 -1 3 3 0 2\n",n);
987 0 0 } else if (S[0] == 0 && S[5] == n-1 && S[2] != S[3] &&
0 0 } else if (S[0] == 0 && S[5] == n-1 && S[2] != S[3] &&
988 0 0 addmod(S[2],S[3],n) == n-3 && sqrmod(submod(S[2],S[3],n),n) == n-(23%n)) {
989 0 0 MPUverbose(2, "%"UVuf" I-Type 0 -1 %"UVuf" %"UVuf" 0 -1\n",n, S[2], S[3]);
994 0 1 MPUverbose(2, "%"UVuf" ? %2d ? %"UVuf" -1 %"UVuf" %"UVuf" 0 %"UVuf"\n", n, jacobi, S[0],S[2],S[3],S[5]);
1005 0 28 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
1006 28 0 if ((n % 2) == 0 || n == UV_MAX) return 0;
0 28 if ((n % 2) == 0 || n == UV_MAX) return 0;
1008 0 28 if (P == 0 && Q == 0) {
0 0 if (P == 0 && Q == 0) {
1010 0 0 if (n == 7) P = 1; /* So we don't test kronecker(-7,7) */
1013 0 0 if (P == 3) P = 5; /* P=3,Q=2 -> D=9-8=1 => k=1, so skip */
1017 0 0 if (P == 10001 && is_perfect_square(n)) return 0;
0 0 if (P == 10001 && is_perfect_square(n)) return 0;
1018 0 0 } while (k == 1);
1019 0 0 if (k == 0) return 0;
1021 0 0 MPUverbose(1, "%"UVuf" Frobenius (%"IVdf",%"IVdf") : x^2 - %"IVdf"x + %"IVdf"\n", n, P, Q, P, Q);
1026 11 17 if (D != 5 && is_perfect_square(Du))
0 11 if (D != 5 && is_perfect_square(Du))
1033 0 28 if (Qk != 1) {
1034 0 0 if (Qk == n) return !!is_prob_prime(n);
1037 28 0 if (k == 0) {
1039 0 28 if (k == 0) return 0;
1040 24 4 if (k == 1) {
1044 4 0 Vcomp = (Q >= 0) ? Qu : n-Qu;
1050 28 0 if (U == 0 && V == Vcomp) return 1;
28 0 if (U == 0 && V == Vcomp) return 1;
1073 0 102 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
1074 102 0 if ((n % 2) == 0 || n == UV_MAX) return 0;
0 102 if ((n % 2) == 0 || n == UV_MAX) return 0;
1075 0 102 if (is_perfect_square(n)) return 0;
1077 49 53 if (n % 4 == 3) c = d;
1078 20 33 else if (n % 8 == 5) c = 2;
1082 47 1 if (c==9 || (c>=15 && (!(c%3) || !(c%5) || !(c%7) || !(c%11) || !(c%13))))
0 47 if (c==9 || (c>=15 && (!(c%3) || !(c%5) || !(c%7) || !(c%11) || !(c%13))))
0 0 if (c==9 || (c>=15 && (!(c%3) || !(c%5) || !(c%7) || !(c%11) || !(c%13))))
0 0 if (c==9 || (c>=15 && (!(c%3) || !(c%5) || !(c%7) || !(c%11) || !(c%13))))
0 0 if (c==9 || (c>=15 && (!(c%3) || !(c%5) || !(c%7) || !(c%11) || !(c%13))))
0 0 if (c==9 || (c>=15 && (!(c%3) || !(c%5) || !(c%7) || !(c%11) || !(c%13))))
0 0 if (c==9 || (c>=15 && (!(c%3) || !(c%5) || !(c%7) || !(c%11) || !(c%13))))
1085 15 33 } while (k == 1);
1086 88 14 if (k == 0 || (k == 2 && n % 3 == 0)) return 0;
69 19 if (k == 0 || (k == 2 && n % 3 == 0)) return 0;
25 44 if (k == 0 || (k == 2 && n % 3 == 0)) return 0;
1093 44 19 ra = a = ea = (k == 2) ? mont_get2(n) : mont1;
1095 1922 63 while (d) {
1096 921 1001 if (d & 1) {
1098 0 921 ra = addmod( mont_mulmod(ta,a,n), mont_mulmod(mont_mulmod(tb,b,n),montc,n), n );
0 0 ra = addmod( mont_mulmod(ta,a,n), mont_mulmod(mont_mulmod(tb,b,n),montc,n), n );
0 921 ra = addmod( mont_mulmod(ta,a,n), mont_mulmod(mont_mulmod(tb,b,n),montc,n), n );
0 921 ra = addmod( mont_mulmod(ta,a,n), mont_mulmod(mont_mulmod(tb,b,n),montc,n), n );
1099 0 921 rb = addmod( mont_mulmod(tb,a,n), mont_mulmod(ta,b,n), n);
0 921 rb = addmod( mont_mulmod(tb,a,n), mont_mulmod(ta,b,n), n);
1102 1859 63 if (d) {
1103 0 1859 UV t = mont_mulmod(mont_mulmod(b,b,n),montc,n);
0 0 UV t = mont_mulmod(mont_mulmod(b,b,n),montc,n);
0 1859 UV t = mont_mulmod(mont_mulmod(b,b,n),montc,n);
1104 0 1859 b = mont_mulmod(b,a,n);
1106 0 1859 a = addmod(mont_mulmod(a,a,n),t,n);
1109 9 54 return (ra == ea && rb == n-mont1);
9 0 return (ra == ea && rb == n-mont1);
1150 0 102 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
0 0 if (n < 7) return (n == 2 || n == 3 || n == 5);
1151 102 0 if ((n % 2) == 0 || n == UV_MAX) return 0;
0 102 if ((n % 2) == 0 || n == UV_MAX) return 0;
1153 200 0 for (x = 0; x < 1000000; x++) {
1154 187 13 if (x==2 || x==4 || x==7 || x==8 || x==10 || x==14 || x==16 || x==18)
180 7 if (x==2 || x==4 || x==7 || x==8 || x==10 || x==14 || x==16 || x==18)
178 2 if (x==2 || x==4 || x==7 || x==8 || x==10 || x==14 || x==16 || x==18)
176 2 if (x==2 || x==4 || x==7 || x==8 || x==10 || x==14 || x==16 || x==18)
176 0 if (x==2 || x==4 || x==7 || x==8 || x==10 || x==14 || x==16 || x==18)
176 0 if (x==2 || x==4 || x==7 || x==8 || x==10 || x==14 || x==16 || x==18)
176 0 if (x==2 || x==4 || x==7 || x==8 || x==10 || x==14 || x==16 || x==18)
0 176 if (x==2 || x==4 || x==7 || x==8 || x==10 || x==14 || x==16 || x==18)
1158 86 90 if (j == -1) break;
1159 74 16 if (j == 0 || (x == 20 && is_perfect_square(n)))
0 74 if (j == 0 || (x == 20 && is_perfect_square(n)))
0 0 if (j == 0 || (x == 20 && is_perfect_square(n)))
1162 0 86 if (x >= 1000000) croak("FU test failure, unable to find suitable a");
1164 18 68 if (t1 != 1 && t1 != n)
18 0 if (t1 != 1 && t1 != n)
1167 2004 68 { UV v = np1; len = 1; while (v >>= 1) len++; }
1179 37 31 if (x == 0) {
1181 1097 37 for (bit = len-2; bit >= 0; bit--) {
1183 0 1097 b = mont_mulmod(submod(b, a, n), addmod(b, a, n), n);
1184 0 1097 a = mont_mulmod(a, t1, n);
1185 507 590 if ( (np1 >> bit) & UVCONST(1) ) {
1194 907 31 for (bit = len-2; bit >= 0; bit--) {
1195 0 907 t1 = addmod( mont_mulmod(a, x, n), addmod(b, b, n), n);
1196 0 907 b = mont_mulmod(submod(b, a, n), addmod(b, a, n), n);
1197 0 907 a = mont_mulmod(a, t1, n);
1198 419 488 if ( (np1 >> bit) & UVCONST(1) ) {
1201 0 419 a = addmod( mont_mulmod(a, multiplier, n), t1, n);
1205 16 52 return (a == 0 && b == result);
16 0 return (a == 0 && b == result);
1256 113403 2265 for (i = 0; i < NUM_KNOWN_MERSENNE_PRIMES; i++)
1257 17 113386 if (p == _mersenne_primes[i])
1259 2265 0 return (p < LAST_CHECKED_MERSENNE) ? 0 : -1;
1265 0 0 if (p == 2) return 1;
1266 0 0 if (!is_prob_prime(p)) return 0;
1267 0 0 if (p > BITS_PER_WORD) croak("lucas_lehmer with p > BITS_PER_WORD");
1270 0 0 for (k = 3; k <= p; k++) {
1286 4 77958 if (x < 13) return (x == 2 || x == 3 || x == 5 || x == 7 || x == 11);
4 0 if (x < 13) return (x == 2 || x == 3 || x == 5 || x == 7 || x == 11);
4 0 if (x < 13) return (x == 2 || x == 3 || x == 5 || x == 7 || x == 11);
4 0 if (x < 13) return (x == 2 || x == 3 || x == 5 || x == 7 || x == 11);
2 2 if (x < 13) return (x == 2 || x == 3 || x == 5 || x == 7 || x == 11);
2 0 if (x < 13) return (x == 2 || x == 3 || x == 5 || x == 7 || x == 11);
1287 77958 0 if (!(x&1) || !(x%3) || !(x%5) || !(x%7) || !(x%11) ) return 0;
77958 0 if (!(x&1) || !(x%3) || !(x%5) || !(x%7) || !(x%11) ) return 0;
77958 0 if (!(x&1) || !(x%3) || !(x%5) || !(x%7) || !(x%11) ) return 0;
77924 34 if (!(x&1) || !(x%3) || !(x%5) || !(x%7) || !(x%11) ) return 0;
122 77802 if (!(x&1) || !(x%3) || !(x%5) || !(x%7) || !(x%11) ) return 0;
1298 6363 233842 if (n < 11) {
1299 6363 0 if (n == 2 || n == 3 || n == 5 || n == 7) return 2;
3465 2898 if (n == 2 || n == 3 || n == 5 || n == 7) return 2;
1484 1981 if (n == 2 || n == 3 || n == 5 || n == 7) return 2;
1283 201 if (n == 2 || n == 3 || n == 5 || n == 7) return 2;
1304 3524 230318 if (n > UVCONST(4294967295)) { /* input is >= 2^32, UV is 64-bit*/
1305 3434 90 if (!(n%2) || !(n%3) || !(n%5) || !(n%7)) return 0;
2536 898 if (!(n%2) || !(n%3) || !(n%5) || !(n%7)) return 0;
2187 349 if (!(n%2) || !(n%3) || !(n%5) || !(n%7)) return 0;
273 1914 if (!(n%2) || !(n%3) || !(n%5) || !(n%7)) return 0;
1306 1767 147 if (!(n%11) || !(n%13) || !(n%17) || !(n%19) ||
1655 112 if (!(n%11) || !(n%13) || !(n%17) || !(n%19) ||
1566 89 if (!(n%11) || !(n%13) || !(n%17) || !(n%19) ||
1497 69 if (!(n%11) || !(n%13) || !(n%17) || !(n%19) ||
1447 50 if (!(n%11) || !(n%13) || !(n%17) || !(n%19) ||
1307 1402 45 !(n%23) || !(n%29) || !(n%31) || !(n%37) ||
1358 44 !(n%23) || !(n%29) || !(n%31) || !(n%37) ||
1323 35 !(n%23) || !(n%29) || !(n%31) || !(n%37) ||
1302 21 !(n%23) || !(n%29) || !(n%31) || !(n%37) ||
1308 1277 25 !(n%41) || !(n%43) || !(n%47) || !(n%53)) return 0;
1258 19 !(n%41) || !(n%43) || !(n%47) || !(n%53)) return 0;
18 1240 !(n%41) || !(n%43) || !(n%47) || !(n%53)) return 0;
1309 1213 27 if (!(n%59) || !(n%61) || !(n%67) || !(n%71)) return 0;
1194 19 if (!(n%59) || !(n%61) || !(n%67) || !(n%71)) return 0;
1186 8 if (!(n%59) || !(n%61) || !(n%67) || !(n%71)) return 0;
11 1175 if (!(n%59) || !(n%61) || !(n%67) || !(n%71)) return 0;
1310 1166 9 if (!(n%73) || !(n%79) || !(n%83) || !(n%89)) return 0;
1155 11 if (!(n%73) || !(n%79) || !(n%83) || !(n%89)) return 0;
1144 11 if (!(n%73) || !(n%79) || !(n%83) || !(n%89)) return 0;
14 1130 if (!(n%73) || !(n%79) || !(n%83) || !(n%89)) return 0;
1319 210707 19611 if (!(x%2) || !(x%3) || !(x%5) || !(x%7)) return 0;
159326 51381 if (!(x%2) || !(x%3) || !(x%5) || !(x%7)) return 0;
137780 21546 if (!(x%2) || !(x%3) || !(x%5) || !(x%7)) return 0;
14800 122980 if (!(x%2) || !(x%3) || !(x%5) || !(x%7)) return 0;
1320 2885 120095 if (x < 121) /* 11*11 */ return 2;
1321 112557 7538 if (!(x%11) || !(x%13) || !(x%17) || !(x%19) ||
105617 6940 if (!(x%11) || !(x%13) || !(x%17) || !(x%19) ||
99940 5677 if (!(x%11) || !(x%13) || !(x%17) || !(x%19) ||
94443 5497 if (!(x%11) || !(x%13) || !(x%17) || !(x%19) ||
90726 3717 if (!(x%11) || !(x%13) || !(x%17) || !(x%19) ||
1322 89025 1701 !(x%23) || !(x%29) || !(x%31) || !(x%37) ||
85710 3315 !(x%23) || !(x%29) || !(x%31) || !(x%37) ||
83769 1941 !(x%23) || !(x%29) || !(x%31) || !(x%37) ||
81940 1829 !(x%23) || !(x%29) || !(x%31) || !(x%37) ||
1323 78972 2968 !(x%41) || !(x%43) || !(x%47) || !(x%53)) return 0;
78285 687 !(x%41) || !(x%43) || !(x%47) || !(x%53)) return 0;
2006 76279 !(x%41) || !(x%43) || !(x%47) || !(x%53)) return 0;
1324 13699 62580 if (x < 3481) /* 59*59 */ return 2;