You might want to start reading at
http://mathworld.wolfram.com/PrimalityTest.html.
It's only recent that someone discovered a "efficient"
algorithm to determine the primality of a number. But it's
still an algorithm that's bounded by the 12th power of the
number of bits the number is written in. There are faster
algorithms, but they either may give false positives, or
false negatives. You may want to look into the
Lucas-Lehmer test: http://mathworld.wolfram.com/Lucas-LehmerTest.html
You should realize that this is not a trivial problem.