http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
using this, write a function to tell me if a number is prime
bool aComposite[1025];
void setupArray()
{
}
bool isPrime(int n)
{
return ! aComposite[n];
}
bool isPrime(int n)
{
if (n== 1 || n == 2)
return true;
for (int i = 2; i <= n-1; i++)
if (n % i == 0)
return false;
return true;
}
Thursday, July 22, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment