Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 at 1:17
3  
whatTheOPWantsMaybe[n_Integer] := With[{exp = GCD @@ FactorInteger[n][[All, 2]]}, (n^(1/exp))^ Defer[exp]] ? –  Rojo Feb 17 at 1:19
    
@Rojo Your CamelCase syntax is horrific –  belisarius Feb 17 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 at 2:18
1  
@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 at 3:12
show 3 more comments

2 Answers

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
add comment

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 at 2:22
add comment

Your Answer

 
discard

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.