depends...
If you know the upper limit and you want to use it very often then you can use this:
PHP Code:
const max=10000;
bool isPrime[max];
// ...
for (int i=0; i<max; i++)
isPrime[i] = true;
int i,j;
i = 2;
while (i<max)
{
if (isPrime[i])
{
j = i*i;
while (j<max)
{
isPrime[j] = false;
j*=i;
}
}
i++;
}
// ...
bool Is_Prime(int num)
{
return isPrime[num];
}
__________________