taocp

This site has no text of the book. Keep your own copy of TAOCP next to it. See what is checked.

Exercise · Volume 1 · 1.2.4-41

Exercise 1.2.4-41

not stated yet in Lean solution written

RatingM23
MarkersM (mathematical)
KindK3, find a value: compute a number, a set or a closed form from the written solution
SectionSection 1.2.4 of Volume 1. Companion chapter: Integer functions and elementary number theory

The task

Give a closed form, with floors or ceilings, for the nnth term of the sequence 1,2,2,3,3,3,4,4,4,4,…1, 2, 2, 3, 3, 3, 4, 4, 4, 4, \ldots in which each kk appears kk times.

The exact wording is in your copy of the book.

Hints

Open one hint at a time. Try the exercise again after each.

Hint 1

The value kk occupies the positions after the first 1+2+⋯+(k−1)1 + 2 + \cdots + (k-1) terms, up to position 1+2+⋯+k1 + 2 + \cdots + k.

Hint 2

So ana_n is the least kk with k(k+1)/2≥nk(k+1)/2 \ge n. Solve the quadratic inequality.

Solution

Show the solution

The value kk appears at the positions nn with k(k−1)2<n≤k(k+1)2\tfrac{k(k-1)}{2} < n \le \tfrac{k(k+1)}{2}. So an=ka_n = k for exactly these nn, that is, ana_n is the least integer kk with k(k+1)/2≥nk(k+1)/2 \ge n.

A form with a ceiling. The inequality k2+k−2n≥0k^2 + k - 2n \ge 0 holds for k≥−1+8n+12k \ge \tfrac{-1 + \sqrt{8n+1}}{2} (as k>0k > 0). The least integer kk with this property is an=⌈8n+1−12⌉.a_n = \Bigl\lceil \frac{\sqrt{8n+1} - 1}{2} \Bigr\rceil.

A form with a floor. Claim: an=⌊2n+12⌋a_n = \lfloor \sqrt{2n} + \tfrac12 \rfloor. Let k≥1k \ge 1. Then ⌊2n+12⌋=k  ⟺  k−12≤2n<k+12  ⟺  k2−k+14≤2n<k2+k+14.\lfloor \sqrt{2n} + \tfrac12 \rfloor = k \iff k - \tfrac12 \le \sqrt{2n} < k + \tfrac12 \iff k^2 - k + \tfrac14 \le 2n < k^2 + k + \tfrac14. Here 2n2n, k2−kk^2 - k and k2+kk^2 + k are integers. The left inequality k2−k+14≤2nk^2 - k + \tfrac14 \le 2n means 2n>k2−k2n > k^2 - k, and the right inequality 2n<k2+k+142n < k^2 + k + \tfrac14 means 2n≤k2+k2n \le k^2 + k. These are exactly k(k−1)2<n≤k(k+1)2\tfrac{k(k-1)}{2} < n \le \tfrac{k(k+1)}{2}. □\square

Check

For n=1,…,10n = 1, \ldots, 10 the floor formula gives 1,2,2,3,3,3,4,4,4,41, 2, 2, 3, 3, 3, 4, 4, 4, 4. For n=6n = 6: 12+0.5=3.96\sqrt{12} + 0.5 = 3.96, floor 33. For n=7n = 7: 14+0.5=4.24\sqrt{14} + 0.5 = 4.24, floor 44. The ceiling form gives ⌈(49−1)/2⌉=3\lceil (\sqrt{49} - 1)/2 \rceil = 3 at n=6n = 6 and ⌈(57−1)/2⌉=4\lceil (\sqrt{57} - 1)/2 \rceil = 4 at n=7n = 7. Both forms agree with the sequence for 1≤n<5001 \le n < 500.

Remarks

A form that needs only an integer square root is an=⌊(⌊8n−7⌋+1)/2⌋a_n = \lfloor (\lfloor\sqrt{8n-7}\rfloor + 1)/2 \rfloor (checked for 1≤n<10001 \le n < 1000). This is the triangular root, the inverse of k↦k(k+1)/2k \mapsto k(k+1)/2. Exercise 1.2.4-43 sums a similar step function.

This solution is checked, and a person has not reviewed it yet. The source.

In Lean

not stated yet The exercise is not stated in Lean yet.

The status is computed from the Lean build. The node of the map.

Something is wrong? Report it.