$n$ is a positive integer. The number of solutions of $x^2+2016y^2=2017^n$ is $k$. Write $k$ with $n$.
1. **Define the function \( f(m) \)**:
   Let \( f(m) \) denote the number of solutions \((x, y) \in \mathbb{Z}^2\) to the equation \( x^2 + 2016y^2 = 2017^m \) for all \( m \in \mathbb{Z}^+_0 \). We know that \( f(0) = 2 \) and \( f(1) = 4 \).

2. **Rewrite the equation in \(\mathbb{Z}[\sqrt{-2016}]\)**:
   For \( n \in \mathbb{Z}_{\geq 2} \), rewrite the equation as:
   \[
   (x + \sqrt{-2016}y)(x - \sqrt{-2016}y) = 2017^n
   \]
   If \( 2017 \mid y \), then \( 2017 \mid x \), so we can write:
   \[
   \left( \frac{x}{2017} \right)^2 + 2016 \left( \frac{y}{2017} \right)^2 = 2017^{n-2}
   \]
   where \( \frac{x}{2017}, \frac{y}{2017} \in \mathbb{Z} \).

3. **Count the number of \((x, y)\) such that \( 2017 \nmid y \)**:
   Let \( \omega = \gcd(x + \sqrt{-2016}y, x - \sqrt{-2016}y) \). Then \( \omega \mid 2\sqrt{-2016}y \), so \( |\omega| \mid 4 \times 2016y^2 \) and \( 2017^n \). Thus, \( |\omega| = 1 \), so \( \omega \) is a unit.

4. **Units in \(\mathbb{Z}[\sqrt{-2016}]\)**:
   The units in \(\mathbb{Z}[\sqrt{-2016}]\) are \( \pm 1 \). This gives us:
   \[
   x + \sqrt{-2016}y = (p + q\sqrt{-2016})^n \quad \text{and} \quad x - \sqrt{-2016}y = (p - q\sqrt{-2016})^n
   \]
   which implies \( 2017 = p^2 + 2016q^2 \). There are 4 possible pairs \((p, q) \in \mathbb{Z}^2\).

5. **Recurrence relation for odd \( n \)**:
   For \( n \) odd, we have:
   \[
   f(n) = f(n-2) + 4
   \]

6. **Recurrence relation for even \( n \)**:
   For \( n \) even, let \( n = 2t \). Consider \((x, y)\) such that \( 2017 \nmid y \). Since \( x^2 \equiv y^2 \pmod{2017} \), we get \( x \equiv y \pmod{2017} \) or \( x \equiv -y \pmod{2017} \). These cases are disjoint since \( y \not\equiv 0 \pmod{2017} \).

   - For \( x \equiv y \pmod{2017} \), let \( x = 2017k + y \). We get:
     \[
     2017k^2 + 2ky + y^2 = 2017^{n-1} = (y + k)^2 + 2016k^2
     \]
     If \( 2017 \mid k \), then \( 2017 \mid y + k \), which is a contradiction. Thus, \( 2017 \nmid k \). Since \( n-1 \) is odd, there are 4 possible pairs \((a, b) \in \mathbb{Z}^2\) such that \( 2017^{n-1} = a^2 + 2016b^2 \) and \( 2017 \nmid b \). Among these, 2 pairs satisfy \( a \not\equiv b \pmod{2017} \).

   - For \( x \equiv -y \pmod{2017} \), let \( x = 2017k - y \). We get:
     \[
     2017k^2 - 2ky + y^2 = 2017^{n-1} = (y - k)^2 + 2016(-k)^2
     \]
     This gives a similar result as the previous case.

   Thus, for even \( n \):
   \[
   f(n) = f(n-2) + 2 + 2 = f(n-2) + 4
   \]

7. **Final recurrence relation**:
   Combining both cases, we get:
   \[
   f(n) = f(n-2) + 4 \quad \text{for all} \quad n \in \mathbb{Z}_{\geq 2}
   \]

8. **Induction**:
   Using induction on \( \mathbb{Z}_{\geq 0} \), we can show that \( f(n) = 2 + 4n \).

The final answer is \( \boxed{2 + 4n} \).