Problem

Source: Own (Oliforum contest 2009, round 2/ 5)

Tags: function, logarithms, combinatorics proposed, combinatorics



Define the function $ g(\cdot): \mathbb{Z} \to \{0,1\}$ such that $ g(n) = 0$ if $ n < 0$, and $ g(n) = 1$ otherwise. Define the function $ f(\cdot): \mathbb{Z} \to \mathbb{Z}$ such that $ f(n) = n - 1024g(n - 1024)$ for all $ n \in \mathbb{Z}$. Define also the sequence of integers $ \{a_i\}_{i \in \mathbb{N}}$ such that $ a_0 = 1$ e $ a_{n + 1} = 2f(a_n) + \ell$, where $ \ell = 0$ if $ \displaystyle \prod_{i = 0}^n{\left(2f(a_n) + 1 - a_i\right)} = 0$, and $ \ell = 1$ otherwise. How many distinct elements are in the set $ S: = \{a_0,a_1,\ldots,a_{2009}\}$? (Paolo Leonetti)