Finding a function whose value at $n$ is the $n^{\text{th}}$ prime For positive integers $a$ and $b$, evaluate:
$$f\left ( a,b \right )=\frac{1}{a}\sum_{j=1}^{a}\cos\left ( \frac{2\pi jb}{a} \right )$$
Hence, find a function $g\left ( n \right )$, $n \in \mathbb{Z}$, such that $g(n)=1$ if $n$ is prime and $g(n)=0$ if $n$ is composite.
Use $g(n)$ to construct a function $p\left ( n \right )$ whose value at $n$ is the $n^{\text{th}}$ prime number.
 A: One notes that
$$f(a,b)=\frac{1}{a}\operatorname{Re}\left(\sum_{j=1}^{a}(e^{\frac{2\pi ib}{a}})^j\right) = \begin{cases}1 & b\equiv 0\pmod a\\ e^{\frac{2\pi ib}{a}}\frac{1-e^{\frac{2\pi iba}{a}}}{1-e^{\frac{2\pi ib}{a}}} & b\not\equiv0\pmod a\end{cases} = \begin{cases}1 & b\equiv 0\pmod a\\ 0 & b\not\equiv0\pmod a\end{cases}$$
This allows us to calculate the number of divisors of $b$ by $\sum_{a=2}^{b-1}f(a,b)$.
A: There are several ways, to define the characteristic prime function $g(n)$. Besides $g(n)= \pi(n)-\pi(n-1)$, one could give it as a Dirichlet convolution product of the arithmetic function $\omega(n)$ and the Moebius $\mu$-function. Since we have
$\omega(n)=\sum_{p\mid n}1=\sum_{d\mid n}g(d)$, Moebius inversion formula yields
$$
g(n)=\sum_{d\mid n}\mu\left(\frac{n}{d}\right)\omega(d)=(\mu\ast \omega)(n).
$$
A formula for $p_n$, the $n$-th prime, is
$$
p_n=2+\sum_{k=2}^{2n\log n+2}\left( 1-\lfloor \frac{\pi(k)}{n}\rfloor\right)
$$
for all $n\ge 2$. I admit, that I don't know how to use $f(a,b)$ here.
