2D recurrences and combinatorial arguments

December 21, 2022
Útulek Series, 1 | CF1761D Chapter, 1

Codeforces 1761D has been sitting in my head since it was proposed around a month ago.

Consider two NN-bit binary integers, X,YX,Y. Let f(X,Y)f(X,Y) be the number of carries that occur during the addition of XX and YY. For example,

1  1  1+ 11  0  0 1  0  1  1 1  0  1+   0  011 0  1  1  0 1  0  1+ 101111 1  0  0  0\begin{aligned} &\begin{array}{r} 1_{\ \ }1_{\ \ }1\\ +\ _{1}1_{\ \ }0_{\ \ }0\\ \hline \ 1_{\ \ }0_{\ \ }1_{\ \ }1 \end{array} &\begin{array}{r} \ 1_{\ \ }0_{\ \ }1\\ +\ _{\ \ }0_{\ \ }0_{1}1\\ \hline \ 0_{\ \ }1_{\ \ }1_{\ \ }0 \end{array} & &\begin{array}{r} \ 1_{\ \ }0_{\ \ }1\\ +\ _{1}0_{1}1_{1}1\\ \hline \ 1_{\ \ }0_{\ \ }0_{\ \ }0 \end{array} \end{aligned}

So f(7,4)=1,f(5,1)=1f(7,4)=1,f(5,1)=1, and f(5,3)=3f(5,3)=3.

For a given KNK\leq N, find AN,KA_{N,K}, the number of ordered pairs (X,Y)(X,Y) such that f(X,Y)=Kf(X, Y) = K. For example, for N=3,K=1N=3,K=1, A3,1=15A_{3,1}=15, as the set of ordered pairs is (1,1)(1,1), (1,5)(1,5), (2,2)(2,2), (2,3)(2,3), (3,2)(3,2), (4,4)(4,4), (4,5)(4,5), (4,6)(4,6), (4,7)(4,7), (5,1)(5,1), (5,4)(5,4), (5,6)(5,6), (6,4)(6,4), (6,5)(6,5), (7,4)(7,4), each of which sees exactly one carry during their addition.

For limits, we have 0K<N1e60\leq K<N\leq 1e6, so anything not O(NlnN)O(N\ln{N}) is pushing it.

As Wyatt pointed out, the sponsors of the round, the EZEC team at Pinely, also have a very cute mascot in EZEC-chan!


Pinely \approx Rentec > HRT \approx Jane. \blacksquare

It must bring EZEC-chan great disappointment, then, that I wasn’t able to solve 1761D in-contest. Inspired by Wyatt’s deeper (and most of the time, number theoretical) dives into solving problems, such as 1748D, and learning the theory behind them, I attempt the same here—which, more concretely, means exploring everything remotely related and at least somewhat accessible to a (mostly) elementary mathematician. Hence, this “1761D chapter” of blogposts will hopefully cover a lot of ground, from Pell equations and generating functions, to the Taylor series, linear sieve, and Number Theoretic Transform (NTT). Unfortunately, I don’t know much complex analysis yet, so I’ll try to avoid getting in the weeds where possible.

1 Reduction to Recurrence

I begin each problem with an attempt to find the correct subproblem structure—that is, a method to compose solutions to smaller subproblems into a solution to a larger subproblem. Trivially, this must exist for any problem solvable with dynamic programming (DP) , but I argue that it exists for any algorithmic problem—the loops themselves establish the sequential subproblems to be solved. For example, in Linear Max Gap, I would retroactively argue that two series of subproblems exist: first, the subproblems of finding the range K=AmaxAminK=A_{max}-A_{min}, and secondly, the subproblems of partitioning AiA_i and finding the max gap for each of the bucket prefixes {B1,,Bi}\{B_1,\ldots,B_i\}.

Playing with small examples, I have discovered, is a decent way to sniff out subproblem structure. We have for the 11-bit numbers

A1,0={(0,0),(0,1),(1,0)}=3,A1,1={(1,1)}=1 (with a carry).\begin{aligned} A_{1,0}&=|\{(0,0),(0,1),(1,0)\}|=3,\\ A_{1,1}&=|\{(1,1)\}|=1\text{ (with a carry)}. \end{aligned}

It makes sense to consider whether the leading bit carries as part of the subproblem, as that obviously affects the number of carries when we consider the next bit. Let BN,K,CN,KB_{N,K},C_{N,K} denote the number of ordered pairs of NN bits whose addition shows KK carries, but with the leading, most significant bit not carried and carried, respectively. We then have AN,K=BN,K+CN,KA_{N,K}=B_{N,K}+C_{N,K}, and, considering the 22-bit numbers, we have

B2,0={(00,00),(00,01),(00,10),(00,11),(01,00),(01,10),(10,00),(10,01),(11,00)}=9,C2,0=0,    A2,0=9,B2,1={(01,01)}=1,C2,1={(10,10),(10,11),(11,10)}=3,    A2,1=4B2,2=0,C2,2={(01,11),(11,01),(11,11)}=3,    A2,2=3.\begin{aligned} B_{2,0}&=|\{(00,00),(00,01),(00,10),\\ &(00,11),(01,00),(01,10),\\ &(10,00),(10,01),(11,00)\}|=9,\\ C_{2,0}&=0,\\ \implies A_{2,0}&=9,\\ B_{2,1}&=|\{(01,01)\}|=1,\\ C_{2,1}&=|\{(10,10),(10,11),(11,10)\}|=3,\\ \implies A_{2,1}&=4\\ B_{2,2}&=0,\\ C_{2,2}&=|\{(01,11),(11,01),(11,11)\}|=3,\\ \implies A_{2,2}&=3. \end{aligned}

Thus, the subproblems to consider for 1761D AN,KA_{N,K}, are those of finding Bi,j,Ci,jB_{i,j},C_{i,j} for iN,jKi\leq N,j\leq K. The structure, then, is that for Ai,jA_{i,j}, either 00 or 11 carries can occur in the ii-th bit, and the remaining jj or j1j-1 carries must occur in the less significant i1i-1 bits. Hence,

Ai,j=f(Bi1,j,Ci1,j,Bi1,j1,Ci1,j1)A_{i,j}=f(B_{i-1,j},C_{i-1,j},B_{i-1,j-1},C_{i-1,j-1})

and it is our mission to find ff. Intuitively, ff is linear, as each of Bi1,j,Ci1,j,Bi1,j1,Ci1,j1B_{i-1,j},C_{i-1,j},B_{i-1,j-1},C_{i-1,j-1} should be involved in Ai,jA_{i,j} a constant number of times, based on the bits we select for the ii-th position. Considering the 44 ordered bit pairs possible for the ii-th position, we have

Ai,j=3Bi1,j for bit pairs (0,0),(0,1),(1,0)+1Ci1,j for bit pair (0,0)+1Bi1,j1 for bit pair (1,1+3Ci1,j1 for bit pairs (0,1),(1,0),(1,1).\begin{aligned} A_{i,j}&=3B_{i-1,j}\text{ for bit pairs }(0,0),(0,1),(1,0)\\ &+1C_{i-1,j}\text{ for bit pair }(0,0)\\ &+1B_{i-1,j-1}\text{ for bit pair }(1,1\\ &+3C_{i-1,j-1}\text{ for bit pairs }(0,1),(1,0),(1,1). \end{aligned}

We actually need a finer breakdown of Ai,jA_{i,j} into Bi,jB_{i,j} and Ci,jC_{i,j}, but it is not so difficult to use the same casework we have used already to find this:

Bi,j=3Bi1,j for bit pairs (0,0),(0,1),(1,0)+1Ci1,j for bit pair (0,0),Ci,j=1Bi1,j1 for bit pair (1,1),+3Ci1,j1 for bit pairs (0,1),(1,0),(1,1).\begin{aligned} B_{i,j}&=3B_{i-1,j}\text{ for bit pairs }(0,0),(0,1),(1,0)\\ &+1C_{i-1,j}\text{ for bit pair }(0,0),\\ C_{i,j}&=1B_{i-1,j-1}\text{ for bit pair }(1,1),\\ &+3C_{i-1,j-1}\text{ for bit pairs }(0,1),(1,0),(1,1). \end{aligned}

This I deem a twin two-dimensional recurrence—but I suspect all twin (and likely higher orders) two-dimensional recurrences can be simplified into single two-dimensional recurrences via repeated substitution, as I discovered in-contest. This smells a little like matrices, and we may have to revisit this later on.

Bi,j=3Bi1,j+1Ci1,j=3Bi1,j+Bi2,j1+3Ci1,j1=3Bi1,j+Bi2,j1+3Bi2,j2+9Ci2,j2=3Bi1,j+Bi2,j1+(3Bi2,j2+9Bi3,j3+9Ci3,j3+)=3Bi1,j+Bi2,j1+(3Bi1,j19Bi2,j1)=3Bi1,j+3Bi1,j18Bi2,j\begin{aligned} B_{i,j}&=3B_{i-1,j}+1C_{i-1,j}\\ &=3B_{i-1,j}+B_{i-2,j-1}+3C_{i-1,j-1}\\ &=3B_{i-1,j}+B_{i-2,j-1}+3B_{i-2,j-2}+9C_{i-2,j-2}\\ &=3B_{i-1,j}+B_{i-2,j-1}+(3B_{i-2,j-2}+9B_{i-3,j-3}+9C_{i-3,j-3}+\ldots)\\ &=3B_{i-1,j}+B_{i-2,j-1}+(3B_{i-1,j-1}-9B_{i-2,j-1})\\ &=3B_{i-1,j}+3B_{i-1,j-1}-8B{i-2,j} \end{aligned}

for some initial conditions we will determine later. Similarly,

Ci,j=3Ci1,j+3Ci1,j18Ci2,jC_{i,j}=3C_{i-1,j}+3C_{i-1,j-1}-8C_{i-2,j}

which is frankly quite nice. As Ai,j=Bi,j+Ci,jA_{i,j}=B_{i,j}+C_{i,j}, we have then the very simple reduction to

Ai,j=3Ai1,j+3Ai1,j18Ai1,j2(1.1)A_{i,j}=3A_{i-1,j}+3A_{i-1,j-1}-8A_{i-1,j-2}\tag{1.1}

which gives our titular recurrence. We can determine initial conditions by playing around with the small values; this gives us Ai,0=3iA_{i,0}=3^i for i0i\geq 0 and Ai,i=3i1A_{i,i}=3^{i-1} for i1i\geq 1. As Ai,jA_{i,j} is a two-dimensional recurrence, we may visualize it in a Pascal’s triangle-like manner:

13194327151398154524227(1.2)\begin{matrix} 1\\ 3&1\\ 9&4&3\\ 27&15&13&9\\ 81&54&52&42&27\\ \ldots \end{matrix}\tag{1.2}

with 00-indexed rows and columns, and AN,KA_{N,K} at row NN and column KK. Indeed, A3,1=15A_{3,1}=15, and the sum of each row is a power of two—as the number of ordered pairs of NN-bit numbers is 22N2^{2N}.

It’s unfortunately at this point in-contest that I failed to make any additional progress. Naively, computing AN,KA_{N,K} can be accomplished in Θ(NK)\Theta(NK) via (1.1)(1.1), but this is too slow. Recall that the Fibonacci sequence

Si=Si1+Si2S_i=S_{i-1}+S_{i-2}

which is naively computed in Θ(N)\Theta(N) (similarly via memoization), can also be computed in Θ(lnN)\Theta(\ln N) via repeated squaring of its matrix:

[S2S1S1S0]i=[1110]i=[Si+1SiSiSi1](1.3)\begin{bmatrix} S_2&S_1\\ S_1&S_0 \end{bmatrix}^i=\begin{bmatrix} 1&1\\ 1&0 \end{bmatrix}^i=\begin{bmatrix} S_{i+1}&S_i\\ S_i&S_{i-1} \end{bmatrix}\tag{1.3}

or equivalently via O(lnN)O(\ln N) repeated squaring of the exponents in Binet’s formula

Si=15((1+52)i(152)i)S_i=\frac{1}{\sqrt{5}}((\frac{1+\sqrt{5}}{2})^i -(\frac{1-\sqrt{5}}{2})^i)

under assumption of arbitrary precision arithmetic, which is typically an invalid assumption.

I will note, however, that the set of numbers Fi=a+biF_{\sqrt{i}}=a+b\sqrt{i}, with a,b,iQa,b,i\in\mathbb{Q}, is closed under addition, subtraction, multiplication, and division, and is more generally a field. It must also be that all intermediate operations in computing SiS_i involve numbers from F5F_{\sqrt{5}}. I suppose FiF_{\sqrt{i}} must have a common name, but I am not aware of it. I will further hypothesize that the a,ba,b involved in the operations to compute Binet’s formula likely have simplified numerators and denominators of size Θ(5N/2)\Theta(5^{N/2}) based on the following examples:

(1+5)2=6+25,(1+5)3=16+85,(1+5)3=56+245,\begin{aligned} (1+\sqrt{5})^2&=6+2\sqrt{5},\\ (1+\sqrt{5})^3&=16+8\sqrt{5},\\ (1+\sqrt{5})^3&=56+24\sqrt{5}, \end{aligned}

thus rendering the traditional Θ(lnN)\Theta(\ln N) repeated squaring on Binet’s to actually be Θ(NlnN)\Theta(N\ln N) with the extra Θ(N)\Theta(N) factor coming from dealing with numbers which take Θ(N)\Theta(N) bits to represent in memory.

I must also address here that my runtimes are typically stated in reference to NN as the value of the input, rather than the size (number of bits) of the input, which is typically log\log-size of the value. Some algorithms, such as the vEB tree, are more concisely interpreted with a runtime in terms of the input size, but will primarily not be dealing with those sorts of algorithms.

Anyway, solution (1.3)(1.3) to the one-dimensional Fibonacci recurrence is a glimmer of hope that two-dimensional recurrence (1.1)(1.1) can be solved in O(NlnN)O(N\ln N), or, even better, in Θ(N)\Theta(N) or Θ(lnN)\Theta(\ln N). However, I was not able to come up with such a solution in-contest.

2 Combinatorial Intuition

Tony and I collaborated on a combinatorial solution after the contest. I will hereby put forth the (perhaps yet immature) hypothesis that the subproblem structure discovered by an attempt is largely determined by the initial examples that one plays with—in the same way that a neural network classifier may be largely determined by the initial seed. Anyway, consider the following initial seed:

 1  0  1  0  0   1  1+ 1  01 111  1  01 01 1 1   0  0  0  1   1  0  1.(2.1)\begin{array}{r} \ 1_\ \ 0_\ \ 1\ \ 0 \ \ 0\ \ \ 1\ \ 1\\ +\ _1\ \ 0_1\ 1_11\ \ 1\ \ 0_1\ 0_1\ 1\\ \hline \ 1_\ \ \ 0_\ \ 0_\ \ 0\ \ 1\ \ \ 1\ \ 0\ \ 1 \end{array}.\tag{2.1}

This example stinks of the same subproblem structure as in section (1)(1). I explain below.

When we add a most significant bit to each of the above 77-bit numbers (hence forming a pair of most significant bits), we see a new carry iff the bit pair is (0,1),(1,0)(0,1),(1,0), or (1,1)(1,1). Similarly, if the leading bit were not carried, we would not see a new carry iff the bit pair is (0,0),(0,1)(0,0),(0,1), or (1,1)(1,1). This observation, that whether or not the i+1i+1-th bit carries only depends on the carry status of the ii-th bit, is a case of state space simplification. That is, the carry status of the 1i11\ldots i-1 bits doesn’t influence whether or not the i+1i+1-th bit carries. So, when we move from considering the ii-th bit to considering the i+1i+1-th bit, we don’t have to store Θ(N)\Theta(N) information in our state, but only Θ(1)\Theta(1) information.

Θ(1)\Theta(1) state information is the best one can ask for—so, if we were to consider the states and subproblems as the sum operations of two ii-bit numbers for iNi\leq N, then we process Θ(N)\Theta(N) state information in total, which is within our runtime bounds. This suggests that this subproblem structure is a promising approach. However, attempting a DP solution from this point lands us back with recurrence (1.1)(1.1), which suggests that there are additional simplifications to be made. Indeed, the example (2.1)(2.1) is much longer than the examples we used in section (1)(1), and lends itself to additional insights.

Let’s continue with example (2.1)(2.1). We can represent the carry status of the addition operation of two 77-bit integers as the following 88-bit string representation:

01110011(2.2)\begin{matrix} 0&1&1&1&0&0&1&1 \end{matrix}\tag{2.2}

At this point, this problem smells like the string runs simplification. I will explain below.

Three of the four choices of bit pairs for the i+1i+1-th bit always continues the carry status of the ii-th bit, and one choice always flips the carry status. How many ordered pairs (x1,x2)(x_1,x_2) generate carry status string like representation (2.2)(2.2)?

The carry status always starts out at 00, so one flip will need to be made at index 00. Then, two indices later, another flip, and two indices later, another flip. The final flip occurs at index 66:

01110011ˆˆˆˆ.(2.3)\begin{matrix} 0&1&1&1&0&0&1&1\\ \^{}&&&\^{}&&\^{}&&\^{} \end{matrix}.\tag{2.3}

These four flips only have one choice each for the bit pair at their index. Indeed, in (x1,x2)(x_1,x_2), the flips to carry status 00 necessarily have the bit pair (0,0)(0,0) at that index, and the flips to carry status 11 necessarily have the bit pair (1,1)(1,1) at that index:

10100110111001ˆˆˆˆ.\begin{matrix} &1&0&1&0&0&1&1\\ &0&1&1&1&0&0&1\\ \^{}&&&\^{}&&\^{}&&\^{} \end{matrix}.

So, to create representation (2.2)(2.2) there are 141^4 choices for the four flips, and 343^4 choices for the four non-flip indices, for a total of 8181 ordered pairs of (x1,y1)(x_1,y_1). This is a nice result! We can stop here and, with some work, derive a nice Θ(N)\Theta(N) closed form for AN,KA_{N,K}, but another state space simplification is possible to make that work easier.

With the carry status string representation in (2.2)(2.2), we can derive the number of carries KK from the string which has NN bits of information. I’ve come to find that the bits of information in a representation is a poor heuristic for the ability of a representation to be further simplified—in fact, the count of objects in a representation is typically a better heuristic. Still, representation (2.2)(2.2) has NN objects of information. Representation (2.3)(2.3) transforms this NN-bit number into flips|\text{flips}| numbers each representing the number of bits before the next flip. This is flips|\text{flips}| objects, which is always less than, and better than NN objects.

Finally, since we only care about the number of carries, we need only store the information about the lengths of the 11-carry-status runs, which is a total of 1-runs|\text{1-runs}| objects of information! This gives the following string runs representation of example (2.1)(2.1):

2,3(2.4)2,3\tag{2.4}

where the 22 denotes the run of 1-carry-statuses in indices 00 through 11, and the 33 denotes the run of 1-carry-statuses in indices 44 through 66. Indeed, 2+3=52+3=5 carries as we saw in example (2.1)(2.1).

The string runs representation is generally pretty powerful, and I’ve seen it many times before, most recently in 1767C. There, again, we have binary strings which can be simplified into runs, and furthermore, only the final run matters, lending itself to yet another state space simplification.

Now we’re in the home stretch, which unfortunately is a ton of precise combinatorics. I always find combinatorial solutions difficult to follow unless I work through them myself, and unfortunately I don’t think I’ve done a good enough job here that this isn’t the case.

Taking our state as the runs representation in (2.4)(2.4), we must ask next: how many (x1,x2)(x_1,x_2) correspond with each representation? For rr runs (r=2r=2 in (2.4)(2.4)), we must have 2r2r flips (2r=42r=4 in (2.3)(2.3)), which leads to 3N2r3^{N-2r} or 3N2r+13^{N-2r+1} possible choices of (x1,x2)(x_1,x_2) which generate the flips representation in (2.3)(2.3). The off-by-one difference is due to the position of the final flip—if it is in bit N+1N+1, it frees up an additional bit in the first NN bits for which we have 33 choices.

As discussed, string run representation (2.4)(2.4) contains slightly less information, and thus we expect even more ordered pairs to generate the same representation. Indeed, we no longer know the positions of the 00-carry-status bits, of which there are 33. We must somehow first place the 22 runs in with the 33 00-carry-status bits, and then scale by either 3N2r3^{N-2r} or 3N2r+13^{N-2r+1}.

Smell something? Yeah, that’s America stars and bars (twice-fold).


Please stop asking if I receive unemployment benefits.

Supposing we wanted K0K\geq 0 carries, then, it suffices first to consider the number of runs we use:

i=1K\sum_{i=1}^K

and for each selection of runs, their positioning with the 00-carry-status bits:

i=1K(NK+1i)\sum_{i=1}^K{N-K+1\choose i}

and how those KK carry status bits are distributed among the ii runs:

i=1K(NK+1i)(K1i1)\sum_{i=1}^K{{N-K+1\choose i}{K-1\choose i-1}}

and finally the N2iN-2i or N2i+1N-2i+1 bits which have 33 choices each. Recall that the N2i+1N-2i+1 case only arises if the final run also includes the final, most significant bit, which leaves (NKi1)N-K\choose i-1 run positions which generate this case:

AN,K for K1=i=1K(3N2i(NKi)+3N2i+1(NKi1))(K1i1).A_{N,K}\text{ for }K\geq 1=\\ \sum_{i=1}^K{(3^{N-2i}{N-K\choose i}+3^{N-2i+1}{N-K\choose i-1}){K-1\choose i-1}}.

Indeed, we have in accordance with (1.2)(1.2),

A3,1=(3(21)+9(20))(00)=15.A_{3,1}=(3{2\choose 1}+9{2\choose 0}){0\choose 0}=15.

A3,2=(3(11)+9(10))(10)+(0+1(11))(11)=13.A_{3,2}=(3{1\choose 1}+9{1\choose 0}){1\choose 0}+(0+1{1\choose1}){1\choose 1}=13.

We can also re-index to not use the number of runs, but instead the number of non-leading flips:

AN,K=j=12K3Nj(NKj/2)(K1j/21).(2.5)A_{N,K}=\sum_{j=1}^{2K}{3^{N-j}{N-K\choose \lfloor j/2\rfloor}{K-1\choose \lceil j/2\rceil-1}}.\tag{2.5}

Admittedly, there is an edge case where 2i>N2i>N as seen in A3,2A_{3,2}, which must set 3N2i3^{N-2i} as 00. Otherwise, this is a pretty straightforward implementation. The answer may be large, so we are asked to mod by the prime 1e9+71e9+7. The factorials up to NN can be memoized in Θ(N)\Theta(N), and their inverses naively memoized in Θ(NlnN)\Theta(N\ln N). Queries are then Θ(K)\Theta(K) to compute the KK-term summation, leading to a Θ(K+NlnN)\Theta(K+N\ln N) solution.

Θ(K+NlnN)\Theta(K+N\ln N) Codeforces submission.

The extra Θ(lnN)\Theta(\ln N) factor feels unneeded—indeed, there is an optimization to memoize the factorial inverses in Θ(N)\Theta(N): by starting with 1/N!1/N!, and multiplying down: Θ(N)\Theta(N) Codeforces submission, which is almost 10 times as fast! This also implies that we can find the first NN multiplicative inverses in Θ(N)\Theta(N), which is indeed the case as explained in this comment by mnaeraxr and in an alternate form in this comment by it4.kp.

The important thing here, of course, isn’t the specifics of the combinatorial argument which landed us at (2.5)(2.5), but rather the form of (2.5)(2.5). Evidently, it must be the same solution which solves recurrence (1.1)(1.1), which, upon retrospection, would have been difficult to derive in-contest.

3 Smells Fishy

So, at this point, if the smoke detector isn’t going off, it ought to be replaced. The room is absolutely pungent of something fishy, and frankly, I’m quite the fan of mermaids.


Symbolism.

Here’s why. Recall Pascal’s triangle, the classical two-dimensional recurrence:

111121133114641\begin{matrix} 1\\ 1&1\\ 1&2&1\\ 1&3&3&1\\ 1&4&6&4&1\\ \ldots \end{matrix}

with well-known solution Ti,j=Ti1,j+Ti1,j1=(ij)T_{i,j}=T_{i-1,j}+T_{i-1,j-1}={i\choose j}. Is it a coincidence, that Ti,jT_{i,j}, like the solution to Ai,jA_{i,j} derived in (2.5)(2.5), both contain choose expressions (and optionally, the sum of many choose expressions)?

Ai,j=3Ai1,j+3Ai1,j18Ai1,j2=k=12j3ik(ijk/2)(j1k/21).\begin{aligned} A_{i,j}&=3A_{i-1,j}+3A_{i-1,j-1}-8A_{i-1,j-2}\\ &=\sum_{k=1}^{2j}{3^{i-k}{i-j\choose \lfloor k/2\rfloor}{j-1\choose \lceil k/2\rceil-1}}. \end{aligned}

Recall that Binet’s formula for the Fibonacci numbers is of the form

Si=(some radical)(some radical)i+(some radical)(some radical)iS_i=(\text{some radical})(\text{some radical})^i+(\text{some radical})(\text{some radical})^i

so perhaps it is not so surprising to learn that the solution to the tribonacci numbers Ti=Ti1+Ti2+Ti3T_i=T_{i-1}+T_{i-2}+T_{i-3} is of the form

Ti=(some radical)(some radical)i+(some radical)(some radical)i+(some radical)(some radical)i.\begin{aligned} T_i&=(\text{some radical})(\text{some radical})^i\\ &+(\text{some radical})(\text{some radical})^i\\ &+(\text{some radical})(\text{some radical})^i \end{aligned}.

Anyway, I’m going to take a small detour to introduce a problem I read in Mosteller’s Fifty Challenging Problems in Probability:

A drawer contains red socks and black socks. When two socks are drawn at random (without replacement), the probably that both are red is 1/21/2. How many socks can the drawer contain?

I promise this detour does tie back into 1761D. However, that will have to wait until next time.