Lucas-Carmichael numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Python}}: minor optimization)
m (→‎{{header|Python}}: use the built-in `pow(b,-1,m)` for computing the modular inverse (faster))
Line 500: Line 500:
Uses the [[wp:SymPy|SymPy]] library.
Uses the [[wp:SymPy|SymPy]] library.
<syntaxhighlight lang="python">from sympy.ntheory import sieve, isprime, prime
<syntaxhighlight lang="python">from sympy.ntheory import sieve, isprime, prime
from sympy.core import mod_inverse, integer_nthroot
from sympy.core import integer_nthroot
from math import lcm, gcd, isqrt
from math import lcm, gcd, isqrt


Line 513: Line 513:
hi = min(B // m + 1, max_p)
hi = min(B // m + 1, max_p)


u = l - mod_inverse(m, l)
u = l - pow(m, -1, l)
while u < lo: u += l
while u < lo: u += l
if u > hi: return
if u > hi: return