Microsoft Small Basic
RSS

Navigation





Quick Search
»
Advanced Search »

PoweredBy

Problem 30 solution

RSS
Modified on 2011/02/19 20:22 by 78.240.52.20 Categorized as Errors
If we have a 3 digit number then the maximum sum of the digits to fifth power is 95+95+95 = 3*95 = 177147

If we check the maximum sum of the digits to fifth power for different numbers of digits we find that the maximum number of digits is 6. For larger numbers with more digits, the maximum sum to 5th powers will always be less than the number.

This limits our search to 6 digit numbers.

Still, we mustn't forget to remove 1=1^5 from our result in the end, because since it's not a sum, it's not considered in the result.

For d = 1 To 10
  TextWindow.WriteLine("Max sum of "+d+" digit number to 5th power = "+d*9*9*9*9*9)
EndFor

total = 0
For d1 = 0 To 9
  s1 = d1*d1*d1*d1*d1
  For d2 = 0 To 9
    s2 = d2*d2*d2*d2*d2
    For d3 = 0 To 9
      s3 = d3*d3*d3*d3*d3
      For d4 = 0 To 9
        s4 = d4*d4*d4*d4*d4
        For d5 = 0 To 9
          s5 = d5*d5*d5*d5*d5
          For d6 = 0 To 9
            s6 = d6*d6*d6*d6*d6
            sum = s1+s2+s3+s4+s5+s6
            number = 100000*d1+10000*d2+1000*d3+100*d4+10*d5+d6
            If (sum = number) Then
              TextWindow.WriteLine("Solution found = "+number)
              total = total+number
            EndIf
          EndFor
        EndFor
      EndFor
    EndFor
  EndFor
EndFor

total = total - 1

TextWindow.WriteLine("Total = "+total)

The answer after a few seconds of calculation is 443839

ScrewTurn Wiki version 3.0.5.600. Some of the icons created by FamFamFam.