Throughout the solution we denote the cells of the table by coordinate pairs; (i,j) refers to the j th cell in the i th row. Consider the directed graph, whose vertices are the cells of the board, and the edges are the arrows (i,j)→(j,i+j) for all 0≤i,j≤2n−1. From each vertex (i,j), exactly one edge passes ( to (j,i+jmod2n) ); conversely, to each cell (j,k) exactly one edge is directed (from the cell (k−jmod2n,j)). Hence, the graph splits into cycles. Now, in any coloring considered, the vertices of each cycle should have the same color by the problem condition. On the other hand, if each cycle has its own color, the obtained coloring obviously satisfies the problem conditions. Thus, the maximal possible number of colors is the same as the number of cycles, and we have to prove that this number is 2n. Next, consider any cycle (i1,j1),(i2,j2),…; we will describe it in other terms. Define a sequence (a0,a1,…) by the relations a0=i1,a1=j1,an+1=an+an−1 for all n≥1 (we say that such a sequence is a Fibonacci-type sequence). Then an obvious induction shows that ik≡ak−1(mod2n),jk≡ak(mod2n). Hence we need to investigate the behavior of Fibonacci-type sequences modulo 2n. Denote by F0,F1,… the Fibonacci numbers defined by F0=0,F1=1, and Fn+2= Fn+1+Fn for n≥0. We also set F−1=1 according to the recurrence relation. For every positive integer m, denote by ν(m) the exponent of 2 in the prime factorization of m, i.e. for which 2ν(m)∣m but 2ν(m)+1\m. Lemma 1. For every Fibonacci-type sequence a0,a1,a2,…, and every k≥0, we have ak= Fk−1a0+Fka1. Proof. Apply induction on k. The base cases k=0,1 are trivial. For the step, from the induction hypothesis we get
ak+1=ak+ak−1=(Fk−1a0+Fka1)+(Fk−2a0+Fk−1a1)=Fka0+Fk+1a1
Lemma 2. For every m≥3, (a) we have ν(F3⋅2m−2)=m; (b) d=3⋅2m−2 is the least positive index for which 2m∣Fd; (c) F3⋅2m−2+1≡1+2m−1(mod2m). Proof. Apply induction on m. In the base case m=3 we have ν(F3⋅2m−2)=F6=8, so ν(F3⋅2m−2)=ν(8)=3, the preceding Fibonacci-numbers are not divisible by 8 , and indeed F3⋅2m−2+1=F7=13≡1+4(mod8). Now suppose that m>3 and let k=3⋅2m−3. By applying Lemma 1 to the Fibonacci-type sequence Fk,Fk+1,… we get
F2k=Fk−1Fk+FkFk+1=(Fk+1−Fk)Fk+Fk+1Fk=2Fk+1Fk−Fk2F2k+1=Fk⋅Fk+Fk+1⋅Fk+1=Fk2+Fk+12
By the induction hypothesis, ν(Fk)=m−1, and Fk+1 is odd. Therefore we get ν(Fk2)= 2(m−1)>(m−1)+1=ν(2FkFk+1), which implies ν(F2k)=m, establishing statement (a). Moreover, since Fk+1=1+2m−2+a2m−1 for some integer a, we get
F_{2 k+1}=F_{k}^{2}+F_{k+1}^{2} \equiv 0+\left(