BeerNutts, your function's logic is the wrong way round: it'll return TRUE if a number is not prime, and FALSE otherwise.
bool sieve[65536];long primes[65536], primeCount = 0;void initSieve (){ for (int i = 2; i < 65536; ++i) if (!sieve[i]) for (int j = i * 2; j < 65536; j += i) sieve[i] = true; for (int i = 2; i < 65536; ++i) if (!sieve[i]) primes[primeCount++] = i;}bool isPrime (long n){ // If n fits in the sieve, then it's a simple lookup. if (n < 65536) return !sieve[n]; // Elsewise, test it against each prime that is less than sqrt(n) for (int i = 0; (i < primeCount) && (primes[i] < sqrt(n)); ++i) if (0 == n % primes[i]) return false; return true;}
Signatures? We don't need no steenking signatures!
Edit: Failed to use the English language.
Edit: Removed a rogue 7.
Edited by - Mayrel on November 1, 2001 2:27:02 PM