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.

  • $\begingroup$ You mean integers, right? $\endgroup$
    – Rojo
    Commented Feb 17, 2014 at 1:17
  • 3
    $\begingroup$ whatTheOPWantsMaybe[n_Integer] := With[{exp = GCD @@ FactorInteger[n][[All, 2]]}, (n^(1/exp))^ Defer[exp]] ? $\endgroup$
    – Rojo
    Commented Feb 17, 2014 at 1:19
  • $\begingroup$ @Rojo Your CamelCase syntax is horrific $\endgroup$ Commented Feb 17, 2014 at 2:09
  • $\begingroup$ @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. $\endgroup$
    – NLCJ
    Commented Feb 17, 2014 at 2:18
  • 1
    $\begingroup$ @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. $\endgroup$
    – Z-Y.L
    Commented Feb 17, 2014 at 3:12

2 Answers 2


With[{s = Max[Cases[Log[Rest[Divisors[#]], #], _Integer]]}, {Surd[#, s], s}] &[yourNumberHere]

Not surprisingly, most integers are there own "highest power". Here's from 2 to 1000:

enter image description here


You find the highest exponent for the base b: b^IntegerExponent[n,b]

  • $\begingroup$ The base is not determined upfront, so b and e are basically variables. $\endgroup$
    – NLCJ
    Commented Feb 17, 2014 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.