Given a natural number $n$ and an element $k \in \mathbb{Z}\_n$, how many solutions are there in $\mathbb{Z}\_n$ to the equation $x^2+y^2 =k$? That is, I'm wondering whether there is a mod-$n$ version of the sum of squares function discussed in [this post](https://mathoverflow.net/questions/29644/enumerating-ways-to-decompose-an-integer-into-the-sum-of-two-squares).


As an example, to write 1 as a sum of squares modulo 7, one has permutations of $0^2+1^2$ but also $2^2+2^2$ and $2^2+5^2$ and $5^2+5^2$.



Number of ways to write an integer as a sum of squares modulo $k$
A formula for the quantity you are considering is given is computed by elementary means in <https://arxiv.org/abs/1404.4214> .


In fact, they consider the same counting problem for general quadratic congruences of the form


$$ a\_1 x\_1^2 + \dots + a\_k x\_k^2 \equiv b \mod n .$$


