Okay, so I am absolutely obsessed with prime numbers, and for the past two years or so I've experimented with various schemes for detecting them (much to no avail). Well, last night I fell asleep with my mind complete fixated on the problem (once again!). Suddenly, in the midst of a dream, an equation came to mind, and I instinctively plugged a few numbers into it. Each and every one I tried worked, and I became so excited that I woke up in a cold sweat! I brewed some coffee and got to work on a simple test program. Running the program, my heart sunk as it started spitting out values that failed the test. Damn! But then, as I looked closer at the numbers, I noticed something that caused my hair to literally stand up on end - 561, 1105, 1729, 2465, 2821...these were the first five Carmichael numbers! In other words, my equation was essentially equivalent to Fermat's primality test to every base!!!

Here is the theorem, in detail:

IFF gcd(s(N, N - 1) mod s(N, 1), N) = 1 then N is either a prime or a Carmichael number, where s(N, E) is the sum of powers (eg: 1^E + 2^E ... + N^E).

From a practical viewpoint, I do realize that it may be inefficient to compute (although I haven't yet confirmed that), but nonetheless it does amount to a much more concise generalization of Fermat's Little Theorem.