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
Skullmaster2017: \ai test
33 minutes ago 0 Replies 0 Medals
mtowns39: Mi hermano ___________________ a mi amiga Elisa.
6 hours ago 0 Replies 0 Medals
Moon: MCAT Tutorial: Hydrostatics
12 hours ago 6 Replies 0 Medals
MRichardson84: If angle FBA=7x+6y, what is angle FBA
17 hours ago 2 Replies 0 Medals
bmelson02: Which is the area of a circle with a radius of 5 units
21 hours ago 1 Reply 0 Medals