Let $n$ be a positive integer. Determine the number of sequences $a_0, a_1, \ldots, a_n$ with terms in the set $\{0,1,2,3\}$ such that $$n=a_0+2a_1+2^2a_2+\ldots+2^na_n.$$
Problem
Source: Polish National Olympiad 2015 2nd round, p5
Tags: algebra, number theory, combinatorics
30.08.2019 14:58
The answer is $\lfloor\frac{n}{2}\rfloor+1$ Before solving the problem let us define a few things. We define $b_n$ to be the number of sequences $a_0, a_1, \ldots, a_n$ with terms in the set $\{0,1,2,3\}$ such that $n=a_0+2a_1+2^2a_2+\ldots+2^na_n.$ We define $c_n$ to be the number of sequences in $b_n$ where $a_1=0$. And finally we define $d_n$ to be the number of sequences in $b_n$ where $a_1=3$ We prove the following by induction: $b_n=\lfloor\frac{n}{2}\rfloor+1$ When $n=1$ we know that $b_n=1$ (trivial) when $n=2$ we know that $b_n=2$($a_0=2$,$a_i=0$ for all positive integer i or $a_0=0$,$a_1=1$and $a_i=0$for all $i>1$) Now we assume for all $n\le k$ We claim the following <Claim1>$b_{k+1}=b_{k-1}-d_{k-1}+c_{k+1}$ (Proof) Looking at all the $b_{k+1}$ sequences, we notice that if $a_1\neq 0$, taking 1 away from $a_1$ will produce all the sequences in $b_{k-1}$ except for the ones where $a_1=3$ and so the claim is true <Claim 2> Under the Induction hypothesis, $c_{k+1}-d_{k-1}=1$ for all positive integer $k$ (proof) We notice that if we write $k+1$ in the form $n=a_0+2a_1+2^2a_2+\ldots+2^na_n$ where $a_1=0$, because $a_0$ is either {0,1,2,3} and since k+1 is one of 0,1,2,3 (mod4) there can only be one unique number $i$ such that $a_0=i$ This is same when writing $k-1$ in the form $n=a_0+2a_1+2^2a_2+\ldots+2^na_n$ where $a_1=3$. $a_0$ can only take one unique value of j depending on the value of $k-1(mod4)$. In fact we can prove that $i=j$ as $k+1-(k-1)=2(mod4)$ and this means $i-(2\times3+j)=2(mod4)$ and solving this we get $i=j(mod4)$ which must mean $i=j$ as i and j can only take values from ${0,1,2,3}$. Now consider the number $\frac{k+1-(0\times 2+i)}{4}$ and $\frac{k-1-(3\times2+j)}{4}$. $b_{\frac{k+1-(0\times 2+i)}{4}}=c_{k+1}$ and $b_{\frac{k-1-(3\times2+j)}{4}}=d_{k-1}$ (This is because $a_0$ and $a_1$ are a constant so in order to eliminate them we consider the two numbers $\frac{k+1-(0\times 2+i)}{4}$ and $\frac{k-1-(3\times2+j)}{4}$.) Now $\frac{k+1-(0\times 2+i)}{4}-\frac{k-1-(3\times2+j)}{4}=\frac{j-i}{4}+2$ but we know j-i=0 so we get $\frac{k+1-(0\times 2+i)}{4}-\frac{k-1-(3\times2+j)}{4}=2$ by induction hypothesis,(we can do this because both $\frac{k+1-(0\times 2+i)}{4}$ and $\frac{k-1-(3\times2+j)}{4}$ are less than k) $b_{n+2}-b_n=\lfloor\frac{n+2}{2}\rfloor+1-(\lfloor\frac{n}{2}\rfloor+1)=1$ so $b_{\frac{k+1-(0\times 2+i)}{4}}-b_{\frac{k-1-(3\times2+j)}{4}}=c_{k+1}-d_{k-1}=1$ and we proved Claim 2. Finally coming back to Claim 1, we now know that $b_{k+1}=b_{k-1}-d_{k-1}+c_{k+1}=b_{k-1}+1$ and so by induction $b_{k+1}=\lfloor\frac{k+1}{2}\rfloor+1$ And we are done