Let $f: \mathbb{N} \rightarrow \mathbb{N}$ satisfy

$f(1)=2, f(2)=1, f(3 n)=3 f(n), f(3 n+1)=3 f(n)+2, f(3 n+2)=3 f(n)+1$.

Find how many integers $n \leq 2014$ such that $f(n)=2 n$.
The form of this functional equation suggests looking at the base 3 representation. In this case, one quickly notices that the function $f$ is the function that, in the base 3 representation of $n$, replaces all 2s with 1s and all 1s with 2s. The proof is done by induction on the number of digits in the base 3 representation of $n$.

The integers that satisfy $f(n)=2n$ are the integers whose base 3 representation contains only 1s or 0s. Therefore, we need to count the number of such integers between 0 and 2014 (whose base 3 representation is 2202121): there are 128 (127 if 0 is not counted).