Ask your own question, for FREE!
Computer Science
OpenStudy (anonymous):

Best C++ Program to generate prime numbers. Best C++ Program to generate prime numbers. @Computer Science

7 years ago
OpenStudy (anonymous):

For any given candidate number, the smallest possible divisor is 2, and the largest possible divisor is (candidate / 2). So, for that range of divisors, check the result of (candidate % [modulo] divisor). If any result is zero, then the candidate is not a prime. If none of the divisor yield a zero modulo result, the candidate is a prime. Leave it to you to do your own coding of this algorithm. It's really quite simple.

7 years ago
OpenStudy (anonymous):

im ganna write it in c language which might help ya: all i understanf is that you wanna generate all possible prime numbers (and lets say from 0 to 1000) int count; int i; for(count=0;count<=1000;count ++) { int p=0; for(i=0;i<=count;i++) if(count % i ==0) p++; if(p==2) printf("count\t); }

7 years ago
OpenStudy (anonymous):

hope it will work....try it :D

7 years ago
OpenStudy (anonymous):

I read a webpage that said the best-performing algorithm was the Sieve of Eratosthenes. But it requires O(n) space, where n is the max prime you're looking for. A simpler way is to check divisors from 2 to sqrt(n). To optimize it a little more only test odd n's (ignore 2). To optimize more, only test odd divisors. To optimize more, only test prime divisors. To only test prime divisors, keep a list of primes that you find, and iterate over it when testing divisors (stop when you get to sqrt(n)).

7 years ago
Can't find your answer? Make a FREE account and ask your own question, OR you can help others and earn volunteer hours!
Latest Questions
Heavenblici: Which pair of lines in these poetic passages uses onomatopoeia
5 hours ago 0 Replies 0 Medals
ZoeyBiocth16: math help
12 hours ago 10 Replies 0 Medals
eviant: Math help pls
9 hours ago 4 Replies 1 Medal
Brooklynexe: I CANT DRAW HALP! any tips?
12 hours ago 7 Replies 1 Medal
Jasminexx: why do we have to have art in are life?
6 hours ago 2 Replies 0 Medals
kaylak: calculus help @tranquility
13 hours ago 0 Replies 0 Medals
cathrinerose23: who likes jordans???!!! no seriously, who does???
13 hours ago 4 Replies 0 Medals
cathrinerose23: who likes jordans???!!! no seriously, who does???
14 hours ago 0 Replies 0 Medals
daytonohio: to be the high school valedictorian
14 hours ago 4 Replies 0 Medals