#include <modular_int.hpp>
Definition at line 550 of file modular_int.hpp.
typedef long_int_mul_op<C> long_mul |
Definition at line 555 of file modular_int.hpp.
typedef long_int_rshift_op<C> long_rshift |
Definition at line 556 of file modular_int.hpp.
typedef long_int_sub_op<C> long_sub |
Definition at line 557 of file modular_int.hpp.
typedef unsigned_of_helper<C>::type uC |
Definition at line 554 of file modular_int.hpp.
Definition at line 560 of file modular_int.hpp.
References n.
00560 { 00561 // p != 1 or 2 00562 uC q0; 00563 if (r <= s0) 00564 q0 = (((uC) 1) << (s0+r-1)) / p; 00565 else { 00566 uC p1 = (p == 0) ? ((uC) 1) << s0 : p >> (r-s0); 00567 uC p0 = p & (((uC) -1) >> (n+s0-r)); 00568 uC d = ((uC) 1) << s1; 00569 q0 = d / p1; 00570 uC b = (d % p1) << (r-s0); 00571 uC c = q0 * p0; 00572 if (c >= p) { q0--; c -= p; } 00573 if (b < c) q0--; 00574 } 00575 return q0; 00576 }
Definition at line 579 of file modular_int.hpp.
References _dynamic_inverse_helper< C, D >::m, n, and _dynamic_inverse_helper< C, D >::op().
00579 { 00580 // If p is 1 or 2 then s0 == 0. 00581 // p must be normalized. 00582 if (p == 1) { 00583 if (m+2 <= n) return 2; 00584 if (m+1 <= n) return 1; 00585 return 0; 00586 } 00587 if (p == 2) { 00588 if (m+2 <= n) return 4; 00589 if (m+1 <= n) return 2; 00590 return 1; 00591 } 00592 nat s0 = (s+t-(r-1)) >> 1; 00593 nat s1 = 2*s0 - 1; 00594 uC q0 = _q0 (p, r, s, t, s0, s1); 00595 uC a0 = 0, a1 = 0; 00596 long_mul::op (a1, a0, q0 * q0, p); 00597 if (long_rshift::op_b (a1, a0, r)) a0++; 00598 uC c = (q0 << s0) - a0; 00599 uC d; 00600 if (m+1 <= n || s1+r <= n) { 00601 if (s1+r-1 >= n) d = 0; else d = (((uC) 1) << (s1+r-1)); 00602 d -= c*p; 00603 if (d >= p) { c++; d-=p; } 00604 } 00605 else { 00606 uC d1, e0, e1; 00607 long_mul::op (e1, e0, c, p); 00608 d = 0; 00609 d1 = ((uC) 1) << (s1+r-1-n); 00610 long_sub::op (d1, d, e1, e0); 00611 if ((d1 != 0) || (d >= p)) { c++; d-=p; } 00612 } 00613 uC d2 = d << 1; 00614 c <<= 1; 00615 if ((d2 >= p) || (d2 < d)) { c++; d = d2-p; } else d = d2; 00616 if (s1+1 == s+t-(r-1)) return c; 00617 d2 = d << 1; 00618 c <<= 1; 00619 if ((d2 >= p) || (d2 < d)) c++; 00620 return c; 00621 }
Definition at line 553 of file modular_int.hpp.
Definition at line 552 of file modular_int.hpp.
Definition at line 551 of file modular_int.hpp.