We define recursively the Ulam numbers by setting u1 = 1, u2 = 2, and for each
subsequent integer n, we set n equal to the next Ulam number if it can be written
uniquely as the sum of two different Ulam numbers; e.g.: u3 = 3, u4 = 4, u5 = 6,
etc.
Prove that there are infinitely many Ulam numbers.
Now a D4 BONUS.
3 (=1+2).
Find another Ulam number is that is the sum of two consecutive Ulam numbers.
How about a 3rd one?
(In reply to
The proof and the bonus by Charlie)
Oh, yes, the program producing the list:
Dim crlf$, u(1000), ways, sum(1000), ptr, term(2), terms, tot, n, t1, t2
Private Sub Form_Load()
Form1.Visible = True
Text1.Text = ""
crlf = Chr$(13) + Chr$(10)
u(1) = 1: u(2) = 2: ptr = 3
sum(1) = 1: sum(2) = 3
For n = 3 To 10000
DoEvents
ways = 0: tot = 0: terms = 0
addon ptr - 1
If ways = 1 Then
u(ptr) = n
sum(ptr) = sum(ptr - 1) + n
Text1.Text = Text1.Text & ptr & Str(n)
If t2 = t1 - 1 Then Text1.Text = Text1.Text & " * " & u(t1) & Str(u(t2))
Text1.Text = Text1.Text & crlf
ptr = ptr + 1
End If
Next
Text1.Text = Text1.Text & crlf & " done"
End Sub
Sub addon(wh)
If u(wh) <= n - tot And sum(wh) >= n - tot And terms < 2 Then
terms = terms + 1
term(terms) = wh
tot = tot + u(wh)
If tot = n Then
ways = ways + 1
t1 = term(1): t2 = term(2)
Else
addon (wh - 1)
End If
tot = tot - u(wh)
term(terms) = 0
terms = terms - 1
End If
w = wh - 1
If w > 0 Then
If sum(w) >= n - tot Then
addon w
End If
End If
End Sub
|
Posted by Charlie
on 2017-06-03 14:34:24 |