Surely $f(n)$ is meant to be the indicator function of the range of the function $k\mapsto p(k)-k$, where $p(k)$ denotes the $k$-th prime number. With this supplemented definition, the conjecture is true. Indeed, $n=p(k)-k$ holds if and only if there are $n-1$ composite numbers up to $p(k)$, that is, $a(n-1)<p(k)<a(n)$. Therefore, $f(n)=1$ means that there is a prime number between $a(n-1)$ and $a(n)$. So we have $a(n)=a(n-1)+2$ when $f(n)=1$, and we have $a(n)=a(n-1)+1$ when $f(n)=0$.