Indicator function for multiplies of $n$. From something I saw in of Jack'D Aurizio's answer a while ago. What is reasoning on why the construction of this function works, the connection of indicator variables and roots of unity? How to to derive it from scratch?
$$f(x)=\frac{1^x+(-1)^x}{2}$$
Is an indicator for when $x$ is divisible by $2$. 
$$\frac{1+e^{\frac{2\pi}{3}ix}+e^{\frac{4\pi}{3}i x}}{3}$$
Is an indicator of $x | 3$.
The pattern is,
$$f(x)=\frac{\zeta_1^x+\zeta_2^x+....\zeta_n^x}{n}$$
 A: It's a geometric series. Every $n$th root of unity is a power of a primitive root of unity (for example $\zeta = e^\frac{2\pi i}{n}$). In your sum for $f(x)$, every term will be a power of $\zeta^x$. So the sum is $$f(x) = 1 + \zeta^x + \zeta^{2x} + ... + \zeta^{(n-1)x}$$ Multiplying through by $\zeta^x$, you get the new sum $$\zeta^x f(x) = \zeta^x + ... + \zeta^{nx}$$ However, since $\zeta$ is an $n$th root of unity, $\zeta^{nx} = 1$, and we actually have $$\zeta^x f(x) = \zeta^x + \zeta^{2x} + ... + \zeta^{(n-1)x} + 1 = f(x)$$ Rearranging, $$(\zeta^x - 1)f(x) = 0$$ That means either $\zeta^x = 1$, or $f(x) = 0$. It's not hard to see that $\zeta^x = 1$ if and only if $x$ is a multiple of $n$ (otherwise cycling through the powers of $\zeta$ could not give $n$ distinct numbers, and then $\zeta$ would not be a primitive root as we declared). So if $x$ is not divisible by $n$, the sum is $0$, and if it is, each term is $1$ so the sum is $n$. Dividing the sum by $n$ as you did above would normalize this into the standard indicator function. 
EDIT: The formula you have above can be derived using the geometric series summation formula, which is just $$1 + r + r^2 + ... + r^{n-1} = \frac{r^{n} - 1}{r - 1}$$ That formula can be derived using the same method I used above, except that you can't assume $r^n = 1$ for general $r$. 
A: $$\sum_{k=0}^{n-1} (e^{\frac{2\pi i x}{n}})^k=\frac{e^{2 \pi i x}-1}{e^{\frac{2 \pi i x}{n}}-1}$$
Assuming $e^{\frac{2 \pi i x}{n}} \neq 1$, otherwise $e^{\frac{2 \pi i x}{n}}=1$ and $\sum_{k=0}^{n-1} (e^{\frac{2\pi i x}{n}})^k=n$.
So for $x \mod n \equiv 0$ we have,
$$\frac{1}{n}\sum_{k=0}^{n-1} (e^{\frac{2\pi i x}{n}})^k=\frac{1}{n}n=1$$
In the case where $x$ is an integer but not a multiple of $n$ we have,
$$e^{\frac{2 \pi i x}{n}} \neq 1$$
Otherwise,
$$\frac{2\pi i x}{n}=2\pi i k$$
And,
$$x=nk$$
Contradicting $x$ is not a multiple of $n$.
So in that case $x \not | n$ we have,
$$\frac{1}{n}\sum_{k=0}^{n-1} (e^{\frac{2\pi i x}{n}})^k=0$$
