 One possible formula is based on Wilson's theorem and generates the number 2 many times and all other primes exactly once.There is also a set of Diophantine equations in nine variables and one parameter with the following property