The Mian–Chowla sequence is an integer sequence defined recursively.



Mian–Chowla is an infinite instance of a Sidon sequence, and belongs to the class known as B₂ sequences.



The sequence starts with:

a1 = 1
then for n > 1, an is the smallest positive integer such that every pairwise sum

ai + aj 
is distinct, for all i and j less than or equal to n.

The Task

 Find and display, here, on this page the first 30 terms of the Mian–Chowla sequence.
 Find and display, here, on this page the 91st through 100th terms of the Mian–Chowla sequence.


Demonstrating working through the first few terms longhand:

a1 = 1
1 + 1 = 2
Speculatively try a2 = 2

1 + 1 = 2
1 + 2 = 3
2 + 2 = 4
There are no repeated sums so 2 is the next number in the sequence.

Speculatively try a3 = 3

1 + 1 = 2
1 + 2 = 3 
1 + 3 = 4
2 + 2 = 4
2 + 3 = 5
3 + 3 = 6
Sum of 4 is repeated so 3 is rejected.

Speculatively try a3 = 4

1 + 1 = 2
1 + 2 = 3
1 + 4 = 5
2 + 2 = 4
2 + 4 = 6
4 + 4 = 8
There are no repeated sums so 4 is the next number in the sequence.

And so on...

See also

 OEIS:A005282 Mian-Chowla sequence
Module Module1
Function MianChowla(ByVal n As Integer) As Integer()
        Dim mc(n - 1) As Integer, sums, ts As New HashSet(Of Integer),
        sum As Integer : mc(0) = 1 : sums.Add(2)
        For i As Integer = 1 To n - 1
            For j As Integer = mc(i - 1) + 1 To Integer.MaxValue
                mc(i) = j
                For k As Integer = 0 To i
                    sum = mc(k) + j
                    If sums.Contains(sum) Then ts.Clear() : Exit For
                    ts.Add(sum)
                Next
                If ts.Count > 0 Then sums.UnionWith(ts) : Exit For
            Next
        Next
        Return mc
    End Function
 
    Sub Main(ByVal args As String())
        Const n As Integer = 100
        Dim sw As New Stopwatch(), str As String = " of the Mian-Chowla sequence are:" & vbLf
        sw.Start() : Dim mc As Integer() = MianChowla(n) : sw.Stop()
        Console.Write("The first 30 terms{1}{2}{0}{0}Terms 91 to 100{1}{3}{0}{0}" &
            "Computation time was {4}ms.{0}", vbLf, str,
            String.Join(" ", mc.Take(30)), String.Join(" ", mc.Skip(n - 10)), sw.ElapsedMilliseconds)
    End Sub
End Module