Given a prime $p$ and a positive integer $k$, an integer $n$ with $0 \le n < p$ is called a $(p, k)$-Hofstadterian residue if there exists an infinite sequence of integers $n_0, n_1, n_2, \ldots$ such that $n_0 \equiv n$ and $n_{i + 1}^k \equiv n_i \pmod{p}$ for all integers $i \ge 0$. If $f(p, k)$ is the number of $(p, k)$-Hofstadterian residues, then compute $\displaystyle \sum_{k = 1}^{2016} f(2017, k)$.

Let's think step by step and output the final answer within \boxed{}.
user