# 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.

• Please specify what you've tried. Also, may I ask whether you've seen basic notions in complex analysis? – Jonathan Y. Aug 9 '13 at 12:11
• Define $g(n)=\pi (n)-\pi(n-1)$ with the prime counting function. – Dietrich Burde Aug 9 '13 at 12:21
• I'm not sure what is more to define in $g(n)$... Is the question to define it in terms of $f$ ? – Denis Aug 9 '13 at 12:22
• I tried to evaluate this series: $\cos(x)+\cos(2x)+\cos(3x)+\cdots+cos(nx)$ where $x=\frac{2\pi b}{a}$ – please delete me Aug 9 '13 at 12:35
• I think this can help, prove that: $$\sum_{k=1}^{n}\cos(kx)=\frac{\sin\left ( n+\frac{1}{2} \right )x}{\sin\left ( \frac{x}{2} \right )}-\frac{1}{2}$$ How can I prove this? After that I would substitute $x$ with $\frac{2\pi b}{a}$ and find when $f(a,b)=0$ – please delete me Aug 9 '13 at 13:11

## 2 Answers

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)$.

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.