As you remark, it is enough to prove that
$$\sum_{k = 1}^n\frac{\cos\left(\frac{2\pi Nk}{n}\right)}{n} = \begin{cases}1, &n\mid N\\0 & n\nmid N.\end{cases}$$
Note that since $n$ is fixed, it is equivalent to show
$$\sum_{k = 1}^n\cos\left(\frac{2\pi Nk}{n}\right) = \begin{cases}n, &n\mid N\\0 & n\nmid N.\end{cases}$$
First, if $n\mid N,$ we have $nm = N$ for some integer $N.$ Then it follows that
$$
\sum_{k = 1}^n\cos\left(\frac{2\pi Nk}{n}\right) = \sum_{k = 1}^n\cos(2\pi mk) = \sum_{k = 1}^n 1 = n.
$$
Now, recall that $\cos(x) + i\sin(x) = e^{ix},$ so that we have
$$
\sum_{k = 1}^n\cos\left(\frac{2\pi Nk}{n}\right) = \Re\left(\sum_{k = 1}^n\left(\cos\left(\frac{2\pi Nk}{n}\right) + i\sin\left(\frac{2\pi Nk}{n}\right)\right)\right) = \Re\left(\sum_{k = 1}^n e^{i\frac{2\pi Nk}{n}}\right).
$$
Thus, it suffices to prove that more generally that if $n\nmid N,$
$$
\sum_{k = 1}^n e^{i\frac{2\pi Nk}{n}} = 0.
$$
Now, set $\zeta_n = e^{2\pi i/n}.$ We know that $\zeta_n$ is a primitive $n$th root of unity, and we have $\zeta_n^{Nk} = e^{i\frac{2\pi Nk}{n}}$. Dividing $N$ by $n,$ we have $N = nq + r$ for some integers $r$ and $q$ with $0 < r < N.$ This implies that $\zeta_n^N = \zeta_n^r.$ If $\gcd(r,n) = 1,$ then $\zeta_n^r$ is a primitive $n$th root of unity as well, and if $\gcd(r,n) = d,$ then $\zeta_n^r$ is a primitive $n/d$-th root of unity.
So, we now need to prove the following:
Lemma: Let $n>2$ be a positive integer. Suppose that $\zeta_n$ is a primitive $n$th root of unity, and let $m$ be a positive multiple of $n.$ Then
$$
\sum_{k = 1}^m\zeta_n^k = 0.
$$
Proof: Writing $m = na$ for some (positive) integer $a,$ we can split up the sum as follows:
\begin{align*}
\sum_{k = 1}^m\zeta_n^k &= \sum_{k = 1}^{an}\zeta_n^k\\
&= \sum_{k = 1}^n\zeta_n^k + \sum_{k = n+1}^{2n}\zeta_n^{k} + \dots + \sum_{k = (a-1)n+1}^{an}\zeta_n^{k}\\
&= \sum_{k = 1}^n\zeta_n^k + \sum_{k = 1}^{n}\zeta_n^{n+k} + \dots + \sum_{k = 1}^{n}\zeta_n^{(a-1)n + k}\\
&= \sum_{k = 1}^n\zeta_n^k + \sum_{k = 1}^{n}\zeta_n^n\zeta_n^k + \dots + \sum_{k = 1}^{n}\zeta_n^{(a-1)n}\zeta_n^{k}\\
&= \sum_{k = 1}^n\zeta_n^k + \sum_{k = 1}^{n}\zeta_n^k + \dots + \sum_{k = 1}^{n}\zeta_n^{k}\\
&= a\sum_{k = 1}^n\zeta_n^k.\\
\end{align*}
So in fact, it is enough to prove that $\sum_{k = 1}^n\zeta_n^k = 0$ if $\zeta_n$ is a primitive $n$th root of unity. However, we have
$$
\zeta_n^n = 1,
$$
which implies that
$$
\zeta_n^n - 1 = 0.
$$
Factoring the left hand side gives
$$
(\zeta_n - 1)(\zeta_n^{n - 1} + \zeta_n^{n-2} + \zeta_n^{n-3} + \dots + \zeta_n^2 + \zeta_n + 1) = 0.
$$
Since $\zeta_n$ is a primitive $n$th root of unity, $\zeta_n - 1\neq 0,$ and so
$$
\zeta_n^{n - 1} + \zeta_n^{n-2} + \zeta_n^{n-3} + \dots + \zeta_n^2 + \zeta_n + 1 = 0.
$$
But $1 = \zeta_n^n,$ so
$$
\zeta_n^n + \zeta_n^{n - 1} + \zeta_n^{n-2} + \zeta_n^{n-3} + \dots + \zeta_n^2 + \zeta_n = 0.
$$
This is exactly what we wanted to prove! $\square$
So, your function does in fact have roots at exactly the primes (supposing that the domain of $f$ is the set of positive integers). However, this doesn't make the Riemann hypothesis unnecessary. We've known formulas for primes for a while, see for example here. I'm not an expert in analytic number theory, but I believe that part of the issue is that the formulas we have for primes are incredibly inefficient. Your formula involves a double sum which has a substantial number of terms, becoming rather computationally heavy as $x$ grows. I would recommend asking an additional question about why formulas for prime numbers (such as yours or the ones in the linked Wikipedia article) don't "make the Riemann hypothesis unnecessary," so that experts on that topic can answer and you can get a better understanding of how the Riemann hypothesis and prime numbers/prime number formulas interact.
Using the Dirac delta or Kronecker delta allows for the nth integers up to x be added together as ones. And bam, a non-recursive form.
– JayZenvia Sep 21 '20 at 00:43