In particular, I want to generalize the following fact:
For any $x \in \mathbb{Z}$, we can write
$\frac{1-(-1)^x}{2}=x \mod 2$
Is it possible to do similarly for any $n\geq 2$? Where we have a function $f$ from $\mathbb{Z}$ to $\{0,\ldots,n-1\}$ such that
$f(x)=x \mod n$
and that f is written in terms of the $n$-roots of unity?