Skip to content

Commit 1517cc8

Browse files
authored
isqrt is expensive
1 parent c7226db commit 1517cc8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/Primes.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,16 @@ function factor!(n::T, h::AbstractDict{K,Int}) where {T<:Integer,K<:Integer}
253253
end
254254

255255
local p::T
256-
nsqrt = isqrt(n)
257256
for p in PRIMES
258-
p > nsqrt && break
259257
while true
260258
q, r = divrem(n, T(p)) # T(p) so julia <1.9 uses fast divrem for `BigInt`
261259
r == 0 || break
262260
h[p] = get(h, p, 0) + 1
263261
n = q
264262
end
265-
n == 1 && return h
266-
nsqrt = isqrt(n)
263+
p*p > n && break
267264
end
265+
n == 1 && return h
268266
isprime(n) && (h[n]=1; return h)
269267
T <: BigInt || widemul(n - 1, n - 1) typemax(n) ? pollardfactors!(n, h) : pollardfactors!(widen(n), h)
270268
end

0 commit comments

Comments
 (0)