# Convert number to exponent form with highest power possible

As a school assignment we have to write a program which solves this issue. Since the program has to run efficient I am wondering what the best way is to approach this issue. Of course there you can just guess and try if it works, but that would not be efficient at all.

Could someone push me in the right direction how to solve: n = b ^ e where e is the largest number possible?

For example, n = 16 would result in 2 ^ 4 instead of 4 ^ 2.

-
You mean integers, right? – Rojo Feb 17 '14 at 1:17
whatTheOPWantsMaybe[n_Integer] := With[{exp = GCD @@ FactorInteger[n][[All, 2]]}, (n^(1/exp))^ Defer[exp]] ? – Rojo Feb 17 '14 at 1:19
@Rojo Your CamelCase syntax is horrific – Dr. belisarius Feb 17 '14 at 2:09
@Rojo, thanks for your comment. Unfortunately I am having trouble understanding the syntax you are using, could you perhaps elaborate this a bit or do you have a link to this syntax? I could not find it in the help center. – NLCJ Feb 17 '14 at 2:18
@NLCJ In @Rojo 's comment, exp=GCD @@ FactorInteger[n][[All,2]] is exp=Apply[GCD,FactorInteger[n][[All,2]]]. This may be make it clearer. – Z-Y.L Feb 17 '14 at 3:12

With[{s = Max[Cases[Log[Rest[Divisors[#]], #], _Integer]]}, {Surd[#, s], s}] &[yourNumberHere]
You find the highest exponent for the base b: b^IntegerExponent[n,b]