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.

I have a quick question. Is there anyway of expressing a large number as a power of another number in Mathematica? By this, I mean for example, $1237940039285380274899124224 = 512^{10}$. Is there a function that enables me to go from the LHS to the RHS of the above calculation? Given $1237940039285380274899124224$, how can I obtain $512^{10}$? Divisors is close but not quite what I need.

Thanks for any useful hints.

share|improve this question
6  
@John Your question doesn't make sense unless you explain why you prefer $512^{10}$ rather than $2^{90}$. This is a special case, in general your expectations are not clear at all. –  Artes Jun 12 '13 at 13:17
1  
@Artes, I wish to express the number in index form with the largest possible base if that makes sense-sry I wasn't explicit from the start. I wish to obtain 512^10 rather than 2^90-It's needed to solve a bigger problem. –  John Jun 12 '13 at 13:20
1  
If it helps I'm trying to solve Euler problem 119. –  John Jun 12 '13 at 13:25
1  
@John Just explain why you prefer $512^{10}$ rather than e.g. $1024^9$ or $32^{18}$. –  Artes Jun 12 '13 at 13:28
1  
@ Artes-here's the problem i'm trying to solve: The number 512 is interesting because it is equal to the sum of its digits raised to some power: 5 + 1 + 2 = 8, and 83 = 512. Another example of a number with this property is 614656 = 284. We shall define an to be the nth term of this sequence and insist that a number must contain at least two digits to have a sum. You are given that a2 = 512 and a10 = 614656. Find a30. –  John Jun 12 '13 at 13:32

1 Answer 1

up vote 4 down vote accepted

Here's a way to brute-force search for numbers that have the property that the sum of the digits raised to an integer power is equal to the number itself.

list = {}; 
Do[If[Total[IntegerDigits[b^e]] == b, 
    AppendTo[list, {b, e}]], {b, 2, 800}, {e, 2, 100}];

This returns a list of the numbers and powers (here's just the first 50), ordered so that they are in numerical order by b^e

ord = Ordering[#[[1]]^#[[2]] & /@ list];
list[[ord]][[1 ;; 50]]

{{9, 2}, {8, 3}, {7, 4}, {17, 3}, {18, 3}, {26, 3}, {27, 3}, {22, 4}, {25, 4}, 
 {28, 4}, {36, 4}, {28, 5}, {18, 6}, {35, 5}, {36, 5}, {46, 5}, {18, 7}, {45, 6}, 
 {27, 7}, {54, 6}, {31, 7}, {34, 7}, {64, 6}, {43, 7}, {53, 7}, {58, 7}, {68, 7}, 
 {46, 8}, {54, 8}, {63, 8}, {54, 9}, {71, 9}, {20, 13}, {81, 9}, {82, 10}, 
 {85, 10},{94, 10}, {97, 10}, {106, 10}, {117, 10}, {40, 13}, {98, 11}, 
 {107, 11}, {108, 11}, {108, 12}, {86, 13}, {103, 13}, {104, 13}, {106, 13}, {107, 13}}

and we can see that with $(8,3)=8^3$ defined as $a_2$, $(28,4)=28^4$ is $a_{10}$ and so on. The 30th is $(63,8)=63^8$.

Doing a google search I now see that this search method is well known, for instance, here and here.

It always makes me nervous using Do. Here's a one-line functional version of the above:

Select[If[Total[IntegerDigits[#[[1]]^#[[2]]]] == #[[1]], {#[[1]], #[[2]]}] & 
   /@ Flatten[Outer[List, Range[2, 600], Range[2, 100]], 1], UnsameQ[#, Null] &]

Set the range for the base in the first of the two Range commands and the range for the exponent in the second Range.

share|improve this answer
    
thanks for posting. I've just tried the code and it seems 58^7 isnt the right answer? Not sure why. 28^4 seems to be the 14th element in your list-why is it the 10th? –  John Jun 12 '13 at 15:53
    
I guess it wasn't obvious to me what the desired ordering is... these are ordered by base number, then exponent. I suppose it might make more sense to order them by value of base^exponent. Shouldn't be hard to sort them... –  bill s Jun 12 '13 at 15:58
    
@John -- see update for reordering. –  bill s Jun 12 '13 at 16:05
    
thanks for pointing that out. It does work! Thanks. –  John Jun 12 '13 at 16:14

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.