
A   taxicab number   (the definition that is being used here)   is a positive integer that can be expressed as the sum of two positive cubes in more than one way.



The first taxicab number is   1729,   which is:

 13   +   123       and also
 93   +   103.


Taxicab numbers are also known as:

   taxi numbers
   taxi-cab numbers
   taxi cab numbers
   Hardy-Ramanujan numbers


Task

 Compute and display the lowest 25 taxicab numbers (in numeric order, and in a human-readable format).
 For each of the taxicab numbers, show the number as well as it's constituent cubes.


Extra credit
 Show the 2,000th taxicab number, and a half dozen more


See also

 A001235: taxicab numbers on The On-Line Encyclopedia of Integer Sequences.
 Hardy-Ramanujan Number on MathWorld.
 taxicab number on MathWorld.
 taxicab number on Wikipedia   (includes the story on how taxi-cab numbers came to be called).


 
Imports System.Text
 
Module Module1
 
    Function GetTaxicabNumbers(length As Integer) As IDictionary(Of Long, IList(Of Tuple(Of Integer, Integer)))
        Dim sumsOfTwoCubes As New SortedList(Of Long, IList(Of Tuple(Of Integer, Integer)))
 
        For i = 1 To Integer.MaxValue - 1
            For j = 1 To Integer.MaxValue - 1
                Dim sum = CLng(Math.Pow(i, 3) + Math.Pow(j, 3))
 
                If Not sumsOfTwoCubes.ContainsKey(sum) Then
                    sumsOfTwoCubes.Add(sum, New List(Of Tuple(Of Integer, Integer)))
                End If
 
                sumsOfTwoCubes(sum).Add(Tuple.Create(i, j))
 
                If j >= i Then
                    Exit For
                End If
            Next
 
            REM Found that you need to keep going for a while after the length, because higher i values fill in gaps
            If sumsOfTwoCubes.AsEnumerable.Count(Function(t) t.Value.Count >= 2) >= length * 1.1 Then
                Exit For
            End If
        Next
 
        Dim values = (From t In sumsOfTwoCubes Where t.Value.Count >= 2 Select t) _
            .Take(2006) _
            .ToDictionary(Function(u) u.Key, Function(u) u.Value)
        Return values
    End Function
 
    Sub PrintTaxicabNumbers(values As IDictionary(Of Long, IList(Of Tuple(Of Integer, Integer))))
        Dim i = 1
        For Each taxicabNumber In values.Keys
            Dim output As New StringBuilder
            output.AppendFormat("{0,10}" + vbTab + "{1,4}", i, taxicabNumber)
 
            For Each numbers In values(taxicabNumber)
                output.AppendFormat(vbTab + "= {0}^3 + {1}^3", numbers.Item1, numbers.Item2)
            Next
 
            If i <= 25 OrElse (i >= 2000 AndAlso i <= 2006) Then
                Console.WriteLine(output.ToString)
            End If
 
            i += 1
        Next
    End Sub
 
    Sub Main()
        Dim taxicabNumbers = GetTaxicabNumbers(2006)
        PrintTaxicabNumbers(taxicabNumbers)
    End Sub
 
End Module