You may enjoy this clip. :)
http://www.ted.com/talks/adam_spencer_why_i_fell_in_love_with_monster_prime_numbers
There is no "formula"..........there are a number of algorithms used in testing for primes....but......so far......nobody has ever developed a foolproof "formula" for detecting whether a specific number is prime, or not
You can read more about this here.....http://en.wikipedia.org/wiki/Prime_number
You may enjoy this clip. :)
http://www.ted.com/talks/adam_spencer_why_i_fell_in_love_with_monster_prime_numbers