I'm interested in the sum:
$$\sum_{k=0}^n {n \choose k} x^k \left( \frac{k}{q} \right)$$
where $q$ is a prime number. This is just the binomial expansion with an extra weight on quadratic residues modulo $q$.
$\it{Motivation:}$
I was trying to find the number of solutions to $x_1^2 + ... + x_n^2 = 1$ with the added condition that $x_i$ and $x_j$ are all distinct modulo $q$.
You can use this formula: The number of solution of $x_1^2 + \cdots + x_k^2 \equiv \lambda \bmod q$
and apply inclusion exclusion on the solutions to get it down to more or less the sum in my question.
So solving the above sum would amount to the same thing as finding distinct $x_i \ne x_j$ solutions to $x_1^2 + ... + x_n^2 = 1$. If we can solve either problem I'd be very happy.