' FB 1.05.0 Win64 ' similar to C Language (first approach) ' timing for i3 @ 2.13 GHz Function endsWith89(n As Integer) As Boolean Dim As Integer digit, sum = 0 Do While n > 0 digit = n Mod 10 sum += digit * digit n \= 10 Wend If sum = 89 Then Return True If sum = 1 Then Return False n = sum sum = 0 Loop End Function Dim As Double start = timer Dim sums(0 To 8 * 81) As UInteger sums(0) = 1 sums(1) = 0 Dim s As Integer For n As Integer = 1 To 8 For i As Integer = n * 81 To 1 Step -1 For j As Integer = 1 To 9 s = j * j If s > i Then Exit For sums(i) += sums(i - s) Next j Next i If n = 8 Then Dim As UInteger count89 = 0 For i As Integer = 1 To n * 81 If Not endsWith89(i) Then Continue For count89 += sums(i) Next i Print "There are";count89; " numbers from 1 to 100 million ending with 89" End If Next Print "Elapsed milliseconds ="; Int((timer - start) * 1000 + 0.5) Print Print "Press any key to quit" Sleep