Fermat primality test
c#, math, primes
Solution
Reading the wikipedia article on the Fermat primality test, You must choose an `a` that is less than the candidate you are testing, not more.
Furthermore, as MattW commented, testing only a single `a` won't give you a conclusive answer as to whether the candidate is prime. You must test many possible `a`s before you can decide that a number is probably prime. And even then, some numbers may appear to be prime but actually be composite.
Problem
I have tried to write a code for Fermat primality test, but apparently failed. So if I understood well: if `p` is prime then `((a^p)-a)%p=0` where `p%a!=0`. My code seems to be OK, therefore most likely I misunderstood the basics. What am I missing here? ``` private bool IsPrime(int candidate) { //checking if candidate = 0 || 1 || 2 int a = candidate + 1; //candidate can't be divisor of candidate+1 if ((Math.Pow(a, candidate) - a) % candidate == 0) return true; return false; } ```