How to find the numbers that are the sum of fifth powers of their digits in VB.NET

1 Answer

0 votes
Imports System
				
Module DigitPowerSum

    ' Computes the sum of the fifth powers of the digits of n
    Function SumOfFifthPowers(n As Integer) As Integer
        Dim sum As Integer = 0
        Dim temp As Integer = n

        While temp > 0
            Dim digit As Integer = temp Mod 10
            sum += digit ^ 5
            temp \= 10
        End While

        Return sum
    End Function

    Sub Main()
        For i As Integer = 1000 To 999999
            If i = SumOfFifthPowers(i) Then
                Console.WriteLine(i)
            End If
        Next
    End Sub

End Module



' run:
'
' 4150
' 4151
' 54748
' 92727
' 93084
' 194979
' 

 



answered Nov 9 by avibootz
...