@@ -384,23 +384,21 @@ julia> radical(2*2*3)
384
384
"""
385
385
radical (n) = prod (factor (Set, n))
386
386
387
- function primepowerfactor! (n:: T , h:: AbstractDict{K,Int} ) where {T<: Integer ,K<: Integer }
388
- r = ceil (Int, inv (log (n, Primes. PRIMES[end ])))+ 1
389
- root = inthroot (n, r)
390
- while r >= 2
391
- if root^ r == n && isprime (root)
392
- h[root] = get (h, root, 0 ) + r
393
- return true
387
+ function factorpower! (n:: Integer , h:: AbstractDict{K,Int} )
388
+ if ispower (n)
389
+ exponent = find_exponent (n)
390
+ root = iroot (n, exponent)
391
+ for (p,freq) in factor (root)
392
+ h[p] += freq * exponent
394
393
end
395
- r -= 1
396
- root = inthroot (n, r)
394
+ return true
397
395
end
398
396
return false
399
397
end
400
398
401
399
function lenstrafactors! (n:: T , h:: AbstractDict{K,Int} ) where {T<: Integer ,K<: Integer }
402
400
isprime (n) && (h[n] = get (h, n, 0 )+ 1 ; return h)
403
- primepowerfactor ! (n:: T , h) && return h
401
+ factorpower ! (n, h) && return h
404
402
# bounds and runs per bound taken from
405
403
# https://www.rieselprime.de/ziki/Elliptic_curve_method
406
404
B1s = Int[2e3 , 11e3 , 5e4 , 25e4 , 1e6 , 3e6 , 11e6 ,
@@ -414,7 +412,7 @@ function lenstrafactors!(n::T, h::AbstractDict{K,Int}) where{T<:Integer,K<:Integ
414
412
if res != 1
415
413
isprime (res) ? h[res] = get (h, res, 0 ) + 1 : lenstrafactors! (res, h)
416
414
n = div (n,res)
417
- primepowerfactor ! (n:: T , h) && return h
415
+ factorpower ! (n, h) && return h
418
416
isprime (n) && (h[n] = get (h, n, 0 ) + 1 ; return h)
419
417
end
420
418
end
0 commit comments