IBM Research | Ponder This | July 2010 solutions
Skip to main content

July 2010

<<June July August>>

Terse solution

The recursion formula xt+3=3xt+2-xt with the initial values of x0=3; x1=3; and x2=9; has the following closed formula xt = at + bt + ct; where a=1+2 cos(20°); b=1-2cos(40°); and c=1-2cos(80°). Since -1<b,c<1 the last two addends are negligible, so xt=round(at). x-1=0, so bounding the cycle gives us a solution like 1027!-1. A more careful calculation gives 217 * 108-1 as the cycle length. The smallest n is actually 169,531,249.


Thanks to Simi Haber, who drew my attention (in his talk "The number of F-matchings in a random tree is almost always a zero residue" given at Noga Alon's combinatorics seminar at Tel-Aviv University) to the cyclic nature of the Fibonacci series modulo N, and thereby gave me the idea for this riddle. The principles applied in this riddle can be used with any recursion formula, and not just with the recursion formula used here. The Fibonacci recursion formula provides one such additional example.

And to Michael Brand for his elaborate solution:

Elaborate solution

Consider the following well-known trigonometric equalities:

(1) cos(x+y) = cos(x)cos(y)-sin(x)sin(y).

(2) sin(x+y) = sin(x)cos(y)+sin(y)cos(x).

(3) cos2(x)+sin2(x) = 1.

From these, it is possible to calculate cos(2x) and cos(3x) as a polynomial of cos(x), as follows:

(4) cos(2x) = cos2(x)-sin2(x) = 2cos2(x)-1.

(5) cos(3x) = cos(2x)cos(x)-sin(2x)sin(x) =
= (2cos2(x)-1)cos(x)-(2sin(x)cos(x))sin(x) =
= 2cos3(x)-cos(x)-2cos(x)sin2(x)=4cos3(x)-3cos(x).

The question asks about cos(20°). Equation (5) gives us the ability to express cos(20°) in terms of cos(3*20°)=cos(60°), which is known to be 0.5.

(6) 0.5=cos(60°)=4*cos3(20°)-3cos(20°).

In other words, instead of trying to calculate cos(20°) explicitly, we can simply treat it as a solution to the polynomial

(7) 4X3 - 3X - 0.5 = 0.

or, in integer coefficients,

(8) 8X3 - 6X – 1 = 0.

Notably, cos(60°)=cos(60°+360°)=cos(60°+720°), so the other two solutions to this cubic polynomial are cos((60°+360°)/3)=cos(140°) and cos((60°+720°)/3)=cos(260°).However, the question does not ask about cos(20°) directly. It asks about 1+2cos(20°). If we substitute

(9) Y=1+2X → X = (Y-1)/2,

into equation (8) we get

(10) 8((Y-1)/2) 3-6((Y-1)/2)-1=0 → (Y3-3Y2+3Y-1) + (-3Y+3) -1 = Y3-3Y2+1 = 0.

We know, therefore, that the three solutions to the polynomial Y3-3Y2+1 = 0 are Y1=1+2cos(20°), Y2=1+2cos(140°) and Y3=1+2cos(260°).
Consider now, a sequence, a0, a1, a2, ..., where a0, a1 and a2 are determined to be some constants, and for any t>2, at=3at-1-at-3. Because 1+2cos(20°), 1+2cos(140°) and 1+2cos(260°) all solve the polynomial Y3 - 3Y2 + 1 = 0, for each of them, the sequence 1, Y, Y2, Y3, ... satisfies the recursion formula (even though it may have different initial conditions than a0, a1, a2).
However, because (1,Y1,Y12), (1,Y2,Y22), (1,Y3,Y32) are three linearly independent vectors, for any choice of (a0,a1,a2) one can find linear coefficients A, B and C, such that
(11) A(1,Y1,Y12)+B(1,Y2,Y22)+C(1,Y3,Y32) = (a0,a1,a2).
Because this linear combination must also satisfy the recursion formula that each of Y1, Y2 and Y3 satisfy, we can also conclude that for any t

(12) at=A Y1t + B Y2t + C Y3t. We are interested in studying round(Y1t). We can do this by looking at at, instead. The reason for this is that

(13) cos(x) < 0 if 90 < x < 270 (mod 360); cos(x) > 0 if x < 90 or x > 270 (mod 360),

from which we know that

(14) Y1>1, -1<Y2,Y3<1.

Y1t is therefore an exponentially increasing sequence, whereas Y2t and Y3t are exponentially diminishing sequences. For a sufficiently large t, at=round(A Y1). In order to get rid of the A factor, we simply choose a0, a1 and a2 such that A=1. The theory of symmetric polynomials guarantees that if we also choose B and C with the same value, the entire sequence will be an integer sequence. (For some more details on this, see the November 2009 Using your Head is Permitted riddle (external link).)
In this particular case, we don't need to invoke the full set of tools provided by symmetric polynomials in order to calculate a0, a1 and a2. They can be found as follows:

(15) a0 = Y10 + Y20 + Y30 = 1 + 1 + 1 = 3.

(16) a1 = Y11 + Y21 + Y31 = (1 + 2cos(20°)) + (1 + 2cos(140°)) + (1 + 2cos(260°)) =
= 3 + 2(cos(20°)+cos(140°)+cos(260°)) = 3.

(17) a2 = Y12 + Y22 + Y32 =
= (1+2cos(20°)) 2+ (1+2cos(140°)) 2 + (1+2cos(260°)) 2 =
= (1+4cos(20°)+4cos2(20°)) + (1+4cos(140°)+4cos2(140°)) + (1+4cos(260°)+4cos2(260°))=
= (1+4cos(20°)+(2cos(40°)+2)) + (1+4cos(140°)+(2cos(280°)+2)) + (1+4cos(260°)+(2cos(520°)+2)) =
= (1+1+1+2+2+2) + 4(cos(20°)+cos(140°)+cos(260°)) + 2(cos(40°)+cos(280°)+cos(520°))=
= 9.

In this derivation we utilized two main facts:

(18) cos2(x) = (cos(2x)+1)/2.


(19) cos(20°)+cos(140°)+cos(260°) = cos(40°)+cos(280°)+cos(520°) = 0;

Equation (18) is a reordering of equation (4). Equation (19) is easier to see if we consider it in the complex domain and use the notation cis(x)=cos(x)+i sin(x):

(20) cis(20°) + cis(140°) + cis(260°) = cis(20°) * (cis(0°)+cis(120°)+cis(240°)) = 0.

(21) cis(40°) + cis(280°) + cis(520°) = cis(40°) * (cis(0°)+cis(240°)+cis(480°)) = 0.

The three vectors form an equilateral triangle in the complex plain, meaning that their sum must be zero. The same is true for the sum of any other full set of roots of unity.

So, we now have the sequence a0=3, a1=3, a2=9, for any t>2, at = 3at-1 – at-3, which we know to be equal to round(Y1t) as soon as t is large enough to allow

(22) |Y2t| + |Y3t| < 0.5.

Let us consider the properties of this sequence, and specifically, let us consider the sequence modulo 109, as we are asked to determine a t value for which, modulo 109 the sequence equals zero. The first observation is that we can calculate the series entirely modulo 109, because in order to calculate the next element modulo 109, we only need to know the preceding elements modulo 109. The rest of their digits do not enter into the calculation.

From now on, we will therefore consider bt= at mod 109, instead of at.
Next, we observe that if any triplet (bt,bt+1,bt+2) equals a triplet at a different set of positions (bs,bs+1,bs+2), the next value, bt+3, will equal bs+3 and, for the same reason, for any positive n, bt+n = bs+n. To see this, simply reuse the argument with (bt+1,bt+2,bt+3) replacing (bt,bt+1,bt+2). This means that from such a point on, the entire function will become cyclic. Moreover, consider that the recursive function can be applied also in reverse:

(23) at = 3at-1 – at-3 → at-3 = 3at-1 – at.

This means that the cyclic behavior, bt+n = bs+n, extends not only to all positive n, but in fact to all integer n. In fact, if we use the inverse recursion formula to extend the at sequence naturally also to negative values of t, the cyclic behavior will continue to hold even if t+n<0 or if s+n<0. Does such a cycle actually occur? Can one actually find such (s,t) pairs? The answer is that such (s,t) pairs must exist, for the simple reason that the domain of bt is finite, and therefore also the domain of (bt, bt+1, bt+2) triplets. There are only 109 possibilities for bt, and at most (109)3=1027 possible triplets. If we look at (b0,b1,b2), (b1,b2,b3), ..., (b10^27, b10^27+1, b10^27+2) at least two of these 1027+1 triplets must be equal. This implies a cycle length of no more than 1027.
Now, we begin to look for a value of t for which bt=0. Though in the sequence b0, b1, b2, ... none of the first few values fits this bill, in the extension to the negatives one is found easily:

(24) b-1 = 3b1 – b2 = 3a1 - a2= 3*3-9 = 0 (mod 109).

Unfortunately, t=-1 is not a valid solution to the riddle (and even if it were, this is a value of t too low for the equality at = round(Y1t) to hold in it.

On the other hand, if we knew the cycle length, L, then the cyclic behavior guarantees that for any integer, k, b-1=bkL-1. Choosing a large enough k will bring us to the useful range of t values, and will solve the riddle.

For this, however, we need to determine the cycle length L, which is not trivial. Instead, we will settle for finding some multiple of it, which works in this case just as well. We know that the cycle length is smaller than or equal to 1027. This means it must be one of a finite set of numbers: 1, 2, 3, ...., 1027. A simple way for finding a value that is a multiple of the cycle length is to multiply all of these together. The result is 1027!, where "!" is the factorial function.

So, for any integer k, bk*(10^27)!-1=0, and for a large enough k, t=k*1027!-1 solves the riddle. We claim that even the choice k=1 provides a large enough t here. To see this, consider that in order to be "large enough", t must satisfy equation (22). However, for this NOT to hold true, Y2 and Y3 must be EXTREMELY close to the value 1 in absolute value. (Their difference from 1 must be on the order of 1/1027!.) This is far from the case, however. Note, for example, that cos(140°) is between cos(135°)=-(√2)/2 and cos(150°) = -0.5. In fact, for t values as low as 10 or 20, the value of |Y2t| + |Y3t| is already very small.

Putting all this together, we see that round((1+2cos(20°))^(1027!-1)) divides 109, and 1027!-1 is a simple-to-compute solution to the riddle (though far from being the minimal one).

If you have any problems you think we might enjoy, please send them in. All replies should be sent to: