-
March 26th, 2002, 02:06 PM
#11
Ah, The Sieve of Eratosthenes. I wrote some on it a while back if anyone is interested:
http://www.cshrp.net/content.aspx?showID=612
Mankan
\"The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise.\"
- Edsger Dijkstra
-
March 26th, 2002, 02:17 PM
#12
Rewandythal> also do b+2 instead of b++. If 2 is eleminated, then no even number can possible go into a.
garathjax> I don't remember exactly which test the ARP test is....and don't have time to look it up right now. I just wanted to warn you that certain tests only work for certain primes. Certain numbers (2^3-1 for example) follow set rules, but that doesnt mean that all primes follow the same rules. Some just make it quick to find. There is a project called the GIMP (I believe) which is working on determining extreamly large prime numbers. The last one was something like 4million digits. Their goal is to find the first prime number greater then 10million digits.
\"Ignorance is bliss....
but only for your enemy\"
-- souleman
-
March 26th, 2002, 02:23 PM
#13
b=2, b+2 takes is straight to 4, missing out 3, I'd have to go from b=1, which would return 1 and would *appear* therefore not to be prime (since a / 1 would be a whole number).
I could of course start at 3, but it'd then miss out the important /2 stage, so 4, for example, would be misreported as prime.
-
March 26th, 2002, 02:30 PM
#14
Code:
int IsPrime(int a)
{
int b;
int c;
if( (a div 2) == (a / 2))
{
c = 1;
}
for(b = 3;b < sqrt(a); b + 2)
{
if( (a div b) == (a / b))
{
c = 1;
}
}
return c;
}
// Returns 0 if prime, 1 if not
This solves the problem, by checking for divisible by 2 first, then starting at 3, incrementing in 2's (all the odd numbers).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|