The number of permutation solutions to a linear equation modulo 2017 This was a question from 'Brilliant.org' and I could not find a solution. The question is

Find the number of 64 tuples $(x_0,x_1,...x_{63})$ such that $x_0,x_1,x_2,...x_{63}$ are distinct elements of $\mathbb{Z}_{2017}$ and $$x_0+x_1+2x_2+3x_3+...+63x_{63}=0\,\,\, \text{mod} \,\, 2017.$$ If your answer is of the form $$n!\left(\binom{m}{n} - m\right),$$ submit $m-n.$

I was trying to write a generating function. But I don't know how to impose the distinct elements condition. Any approach is appreciated!
 A: We will first prove the following lemma.
Lemma. Fix a prime $p$ and define the function $f(k)$ on positive integers by the conditions
$$\begin{aligned}
& f(1, p)=0 \\
& f(k, p)=\frac{(p-1) !}{(p-k) !}-k f(k-1, p) \quad(k>1) .
\end{aligned}$$
Then for any positive integers $a_1, \ldots, a_k$ with $a_1+\cdots+a_k<p$, there are exactly $f(p)$ solutions to the equation $a_1 x_1+\cdots+$ $a_k x_k=0$ with $x_1, \ldots, x_k \in \mathbb{F}_p$ nonzero and pairwise distinct.
Proof. We check the claim by induction, with the base case $k=1$ being obvious. For the induction step, assume the claim for $k-1$. Let $S$ be the set of $k$-tuples of distinct elements of $\mathbb{F}_p$; it consists of $\frac{p !}{(p-k) !}$ elements. This set is stable under the action of $i \in \mathbb{F}_p$ by translation:
$$\left(x_1, \ldots, x_k\right) \mapsto\left(x_1+i, \ldots, x_k+i\right)$$
Since $0<a_1 \cdots+a_k<p$, exactly one element of each orbit gives a solution of $a_1 x_1+\cdots+a_k x_k=0$. Each of these solutions contributes to $f(k)$ except for those in which $x_i=0$ for some $i$. Since then $x_j \neq 0$ for all $j \neq i$, we may apply the induction hypothesis to see that there are $f(k-1, p)$ solutions that arise this way for a given $i$ (and these do not overlap). This proves the claim.
To compute $f(k, p)$ explicitly, it is convenient to work with the auxiliary function
$$g(k, p)=\frac{p f(k, p)}{k !}$$
by the lemma, this satisfies $g(1, p)=0$ and
$$\begin{aligned}
g(k, p) & =\left(\begin{array}{c}
p \\
k
\end{array}\right)-g(k-1, p) \\
& =\left(\begin{array}{c}
p-1 \\
k
\end{array}\right)+\left(\begin{array}{c}
p-1 \\
k-1
\end{array}\right)-g(k-1, p) \quad(k>1) .
\end{aligned}
$$
By induction on $k$, we deduce that
$$
\begin{aligned}
g(k, p)-\left(\begin{array}{c}
p-1 \\
k
\end{array}\right) & =(-1)^{k-1}\left(g(1, p)-\left(\begin{array}{c}
p-1 \\
1
\end{array}\right)\right) \\
& =(-1)^k(p-1)
\end{aligned}
$$
and hence $g(k, p)=\left(\begin{array}{c}p-1 \\ k\end{array}\right)+(-1)^k(p-1)$.
We now set $p=2017$ and count the tuples in question. Define $c_0, \ldots, c_{63}$ as in the first solution. Since $c_0+\cdots+c_{63}=p$, the translation action of $\mathbb{F}_p$ preserves the set of tuples; we may thus assume without loss of generality that $x_0=0$ and multiply the count by $p$ at the end. That is, the desired answer is
$$\begin{aligned}
2017 f(63,2017) & =63 ! g(63,2017) \\
& =63 !\left(\left(\begin{array}{c}
2016 \\
63
\end{array}\right)-2016\right).
\end{aligned}$$
This solution is based on a variation found here.
