Find formula for function of $n$ returning $0$ if $n$ is composite and $1$ if $n$ is prime

I'm not sure what kind of functions are allowed but here is a similar one (might be equivalent after some small changes), the differences being it's finite and doesn't require ability to select primes:

For any positive integer $p$, define this function $$ f(n,p):= \left\lceil \frac{n-p\lfloor \frac{n}{p}\rfloor}{n} \right\rceil $$ If $p$ divides $n$ then $f(n,p)=0$, otherwise $n-p\lfloor n/p\rfloor\neq 0$ so $f(n,p)=1$.

You can then use this to make the following: $$ \theta(n):= n - n\prod_{p=2}^{n-1}f(n,p) $$ If $n$ is composite then one of the $p$'s will make the product $0$ and hence $\theta(n)=n$. Otherwise $n$ is prime and the product is $1$, giving $\theta(n)=0$.


Good try; but there's something that needs fixing. When $n$ is composite, the product diverges to $\infty$; so you should define $\text {sgn} (\infty) = 1$.


Instead of the sign function, you could potentially use the Kronecker delta, which is defined as

$$\delta_{mn}=\begin{cases} 1 & \text{if }n=m\\ 0 & \text{if }n\neq m \end{cases}$$

It basically compares two numbers and gives $1$ if there is a match and $0$ otherwise. By summing over such Kronecker delta's, you could build:

$$\theta(n)=n\sum_{i=1}^{\infty}\delta_{np_i}$$

(where $p_i$ is the $i$-th prime number). However, I'm wondering if this would be accepted because it kind of bypasses the question of "checking if $n$ is prime". Both our formulas are just a nice rewording of the "text-form" formula given in the question, so I'm not certain this was the kind of answer that was expected.