Prime counting function formulas Are there any elementary (including floor, ceiling, mod) representations of the prime counting function. Or one without an integral.
 A: I made this elementary formula, although it really has no practical importance:
for $n > 3$
$\pi (n) =  2 + \sum \limits_{m=4}^{n} \left\lfloor \frac{\displaystyle 1}{\displaystyle 1+ \displaystyle\sum_{p=2}^{\left\lfloor \sqrt{m} \right\rfloor}{\left( \left\lfloor\frac{m}{p}\right\rfloor- \left\lfloor\frac{m-1}{p}\right\rfloor \right)}} \right\rfloor$
if we neglect the multiples of 2 and 3, it can be transformed into the following formula:
$\pi (n) = 2 + \sum \limits_{k=1}^{\left\lfloor{\frac{n+1}{6}}\right\rfloor} {\left\lfloor \frac{\displaystyle 1}{ \displaystyle 1 + \displaystyle\sum_{a=1}^{\left\lfloor\frac{1+\sqrt{-1+6\cdot k}}{6}\right\rfloor} {\left( \left\lfloor\frac{-1+6\cdot k}{-1+6\cdot a}\right\rfloor - \left\lfloor\frac{-2+6\cdot k}{-1+6\cdot a}\right\rfloor \right)} + \displaystyle\sum_{a=1}^{\left\lfloor\frac{-1+\sqrt{-1+6\cdot k}}{6}\right\rfloor} {\left( \left\lfloor\frac{-1+6\cdot k}{1+6\cdot a}\right\rfloor - \left\lfloor\frac{-2+6\cdot k}{1+6\cdot a}\right\rfloor \right)} }\right\rfloor}+\sum \limits_{k=1}^{\left\lfloor{\frac{n-1}{6}}\right\rfloor} {\left\lfloor \frac{\displaystyle 1}{\displaystyle 1 + \displaystyle\sum_{a=1}^{\left\lfloor\frac{1+\sqrt{1+6\cdot k}}{6}\right\rfloor} {\left( \left\lfloor\frac{1+6\cdot k}{-1+6\cdot a}\right\rfloor - \left\lfloor\frac{6\cdot k}{-1+6\cdot a}\right\rfloor \right)} + \displaystyle\sum_{a=1}^{\left\lfloor\frac{-1+\sqrt{1+6\cdot k}}{6}\right\rfloor} {\left( \left\lfloor\frac{1+6\cdot k}{1+6\cdot a}\right\rfloor - \left\lfloor\frac{6\cdot k}{1+6\cdot a}\right\rfloor \right)} }\right\rfloor}$
This is the Matlab code to verify the formula:
n=10000;
Pin=2;
for k=1:floor((n+1)/6)
    Sk=1;
    for a=1:floor((1+sqrt(-1+6*k))/6)
        Sk = Sk + floor((-1+6*k)/(-1+6*a)) - floor((-2+6*k)/(-1+6*a));
    end  
    for a=1:floor((-1+sqrt(-1+6*k))/6)
        Sk = Sk + floor((-1+6*k)/(1+6*a)) -  floor((-2+6*k)/(1+6*a));
    end  
    Pin=Pin+floor(1/Sk);
end
for k=1:floor((n-1)/6)
    Sk =1;
    for a=1:floor((1+sqrt((1+6*k)))/6)
        Sk = Sk + floor((1+6*k)/(-1+6*a)) - floor((6*k)/(-1+6*a));
    end 
    for a=1:floor((-1+sqrt((1+6*k)))/6)
        Sk = Sk + floor((1+6*k)/(1+6*a)) -  floor((6*k)/(1+6*a)) ;
    end 
    Pin=Pin+floor(1/Sk);
end
Pin

A: I know three beautiful formulas for the prime-counting function. You can proof them with Wilson's theorem, which states that
$$(n-1)!\,\equiv -1\mod n \Longleftrightarrow n\in\mathbb{P},\qquad \forall n\geq2.$$
Define a function $X_\mathbb{P}(n)$, which gives $1$ for $n\in\mathbb{P}$ and $0$ for $n\notin\mathbb{P}$. An expression for the prime counting function would be then:
$$\pi(x) = \sum_{n=2}^{x}X_\mathbb{P}(n).$$
I know three closed expressions for $X_\mathbb{P}(n)$ but I think you can find one more. Here they are:
$$F(n) = \left\lfloor\cos^2\left(\pi\cfrac{(n-1)!+1}{n}\right)\right\rfloor$$
$$H(n) = \cfrac{\sin^2{\left(\pi\cfrac{(n-1)!^2}{n}\right)}}{\sin^2\frac{\pi}{n}}$$
$$M(n) = \left\lfloor\left(\cfrac{(n-1)!+1}{n}\right)-\left\lfloor\left(\cfrac{(n-1)!}{n}\right)\right\rfloor\right\rfloor$$
