Hi,
I'm trying to solve the following problem:
for a^b when 0 < a,b < 100 I want to find the maximum sum of digits of the generated numbers. For example 9^3=729, sum=7+2+9=18.
I have the following code:
clear allclcdigits(1000)tot=0;for a=99:-1:1 for b=99:-1:1 Num=vpa(sym(a^b)); dig=double(1+floor(log10(Num)+eps)); Num=Num/10^dig; sumA=0; for i=1:dig+1 sumA = sumA+(floor(Num*(10^(i-1)))-10*floor(Num*10^(i-2))); end temp=double(sumA); if temp == 972 disp(a) disp(b) end endend
Where I found that 88^99 yields the max sum of digits 978, but it's the wrong answer. (correct answer is 972). Does anyone find the error?
Cheers!
Best Answer