I recently found the expression
$$\pi(n)=\sum_{k=1}^n\left\lfloor 2^{m(k)}\right\rfloor,\tag1 \label{eq1}$$ where $$m(k)=2k-1-\sum_{j=1}^{k}\gcd(j,k).$$
I found this by designing a characteristic function for the primes $\chi_{\Bbb P}(n)$. We can write $$p\text{ is prime }\iff \sum_{j=1}^p\gcd(j,p)=2p-1.$$ This comes from $\gcd(j,p)=1$ for all $j<p$. Then we can also write $$p\text{ is not prime }\iff \sum_{j=1}^p\gcd(j,p)>2p-1.$$ Thus the function $m(p)$ is $0$ for prime $p$ and negative for composite $p$. This being the case, $2^{m(p)}=1$ for prime $p$, and $0<2^{m(p)}<1$ for composite $p$. Taking the floor function of $2^{m(p)}$ then gives a working expression for $\chi_{\Bbb P}(p)$. Clearly, $\sum_{p\le n}\chi_{\Bbb P}(p)=\left|\left\{p\in\Bbb P:p\le n\right\}\right|=:\pi(n)$.
Since this is so simple I doubt it is new, but I can't find it anywhere. Is this because it is simply not useful? Or is there some other reason? Any sources which contain \eqref{eq1} or equivalent expressions would be appreciated. :)
This kind of formulas are common. May be this exact variant is new, but there are many others based on $\chi_{\mathbb P}$. For example, for $n>1$ we have $$\chi_{\mathbb P}(n)=\left\lfloor \cos^2\left(\frac{(n-1)!+1}{n}\pi\right)\right\rfloor$$ or $$\chi_{\mathbb P}(n)=\left\lfloor\frac{2}{\sum_{k=1}^n(\lfloor\frac{n}{k}\rfloor-\lfloor\frac{n-1}{k}\rfloor)}\right\rfloor$$
And you guessed right, this kind of formulas are not useful, and that's why they are usually not found in textbooks. I remember to have seen the first one in a book as an exercise after the section of Wilson's theorem.