I spent last week in Spain with friends, among them Andrea and Cristina Benedetti from Italy. On March 29, 2007 Andrea and Cristina gave birth to a beautiful baby boy called Simone. This blog entry is dedicated to my little friend Simone and his parents.

Simone was born on a month day which is a prime number (29), and Andrea told me of interesting experiences he had with the number 29. I'm very fond of numerical observations so naturally I started wondering what other interesting facts are hidden in Simone's birth date. The standard format used to express dates in Italy is dd-mm-yyyy, and I wondered if the integer constituting Simone's full birth date (29032007) was also a prime. So I wrote a T-SQL function called fn_isprime that accepts an input parameter @n of a BIGINT datatype and returns a BIT value as output--0 if the input number is not a prime and 1 if it is.

The function indicated that the number 29032007 is a prime, so naturally I immediately called Andrea (around 1:00 AM, mind you) to tell him the news.

So, here's the challenge--write your own version of fn_isprime. The focus of the puzzle is performance. The faster it is, the more points you get. Please include some narrative to describe your solution.

To test it with large numbers beyond Simone's birth date, here are some primes longer than 8 digits:

09 digits: 100000007
10 digits: 1000000007
11 digits: 10000000019
12 digits: 100000000003
13 digits: 1000000000039
14 digits: 10000000000037
15 digits: 100000000000031
16 digits: 1000000000000037
17 digits: 10000000000000061
18 digits: 100000000000000003
19 digits: 1000000000000000003

Good luck!
--
BG