I have read about Fermat's primality test... it was nice but there was one flaw about Carmichael number... it shows that it coulnd't find the distiguish them with prime numbers..
My code:
bool fermat(long long p,int itr)
{
if(p==1)return false;
for(int i=0;i<itr;i++)
{
long long a=rand()%(p-1)+1;
if(modulo(a,p-1,p)!=1)
return false;
else
return true;
}
}
How can I find that p
is prime without getting into the problem of Carmichael number? Any modification of this algo?