%I #7 Sep 16 2015 13:29:25
%S 1,4,9,13,13,27,36,37,45,45,62,64,71,97,99,99,109,117,127,136,136,148,
%T 153,163,171,197,197,202,224,224,236,236,251,256,281,281,302,302,306,
%U 306,315,352,352,355,360,385,385,396,406,406,431,432,437,441,469,469
%N Maximal sum of decimal digits of a^b for 1 <= a,b <= n.
%C Clearly a(n) <= a(n+1). For what values of n do we have equality? Is there an explicit formula for a(n)?
%H Project Euler, <a href="http://projecteuler.net/index.php?section=problems&id=56">Problem 56: Considering natural numbers of the form a^b, find the maximum digital sum.</a>
%e a(3)=9=2+7 is the digit sum of 3^2 and 3^3=27, all other a^b with a,b <= 3 have smaller digit sum.
%e a(4)=13=2+5+6 is the digit sum of 4^4=256, all other a^b with a,b <= 4 have smaller digit sum.
%e a(5)=13 since also for a,b <= 5 there is no higher digit sum (but the same is obtained for 5^4=625).
%t a = {1}; For[n = 2, n < 100, n++, r = a[[ -1]]; For[j = 1, j < n + 1, j++, If[Max[Plus @@ IntegerDigits[n^j], Plus @@ IntegerDigits[j^n]] > r, r = Max[Plus @@ IntegerDigits[n^j], Plus @@ IntegerDigits[j^n]]]]; AppendTo[a, r]]; a (* _Stefan Steinerberger_, Dec 22 2007 *)
%o (PARI) digitsum(n,s)=n=[n];while(n,n=divrem(n[1],10);s+=n[2]);s A135740(n)=vecmax(matrix(n,n,i,j,digitsum(i^j)))
%K base,nonn
%O 1,2
%A _M. F. Hasler_, Nov 30 2007
%E More terms from _Stefan Steinerberger_, Dec 22 2007
|