Skip to content

Commit

Permalink
Update primes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
teschlg committed Oct 21, 2024
1 parent fad546e commit 4ac720f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kryptools/primes.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ def iroot(k: int, n: int) -> int:
return n
if k == 2:
return isqrt(n)
rr = isqrt(n)
r = isqrt(n)
while r**k >= n:
rr = r
r = isqrt(r)
r =rr + 1
k1 = k-1
while rr < r:
r = rr
rr = (k1 * r + n // r ** k1) // k # Newton iteration
rr = (k1 * rr + n // rr ** k1) // k # Newton iteration
return r

def perfect_power(n: int) -> tuple|None:
Expand Down

0 comments on commit 4ac720f

Please sign in to comment.