Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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]

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

enter image description here

share|improve this answer

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

share|improve this answer
The base is not determined upfront, so b and e are basically variables. – NLCJ Feb 17 '14 at 2:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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