Racket, 83 79 bytes
(λ(n)(cadr(argmax cadr((let()(local-require math/number-theory)factorize)n))))
Try it online!
(I'm not sure if there's a consensus on what constitutes a complete Racket solution, so I'm going with the Mathematica convention that a pure function counts.)
How it works
factorize
gives the factorization as a list of pairs: (factorize 108)
gives '((2 2) (3 3))
. The second element of a pair is given by cadr
, a shorthand for the composition of car
(head of a list) with cdr
(tail of a list).
I feel silly doing (cadr (argmax cadr list))
to find the maximum of the second elements, but max
doesn't work on lists: (max (map cadr list))
doesn't do what we want. I'm not an expert in Racket, so maybe there's a standard better way to do this.
Racket, 93 bytes
(λ(n)(define(p d m)(if(=(gcd m d)d)(+(p d(/ m d))1)0))(p(argmax(λ(d)(p d n))(range 2 n))n))
Try it online!
How it works
An alternative version that doesn't import factorize
and instead does everything from scratch, more or less. The function (p m d)
finds the highest power of d
that divides m
and then we just find highest value of (p n d)
for d
between 2
and n
. (We don't need to restrict this to primes, since there will not be a composite power that works better than prime powers.)