Skip to content

Commit 8c9448b

Browse files
authored
Remove isprime from trial division part of factor (#93)
1 parent 46ca8d9 commit 8c9448b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Primes.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ function factor!(n::T, h::AbstractDict{K,Int}) where {T<:Integer,K<:Integer}
256256
end
257257

258258
local p::T
259+
nsqrt = isqrt(n)
259260
for p in PRIMES
261+
p > nsqrt && break
260262
if n % p == 0
261263
h[p] = get(h, p, 0) + 1
262264
n = div(n, p)
@@ -265,9 +267,10 @@ function factor!(n::T, h::AbstractDict{K,Int}) where {T<:Integer,K<:Integer}
265267
n = div(n, p)
266268
end
267269
n == 1 && return h
268-
isprime(n) && (h[n] = 1; return h)
270+
nsqrt = isqrt(n)
269271
end
270272
end
273+
isprime(n) && (h[n]=1; return h)
271274
T <: BigInt || widemul(n - 1, n - 1) typemax(n) ? pollardfactors!(n, h) : pollardfactors!(widen(n), h)
272275
end
273276

0 commit comments

Comments
 (0)