S Connor wrote:I'm just thinking there needs to be a way to record which numbers are not prime.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:..Now, does that look like the Sieve being the goal of this assignment? I have my doubts...
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
S Connor wrote:Thanks for the advice. I am following an exercise book which ...
S Connor wrote:I'm wondering if there is an elegant solution that does not require recording of which numbers are prime?
S Connor wrote:'How many numbers up to 10,000 do you have to test to ensure that you have found all the primes?'
Well it seems to me that you have to test all the numbers up to 9973 to ensure that you have found them all. But how would you translate this into code?
S Connor wrote:Here is my solution to the first part of the problem...
Junilu Lacar wrote:
S Connor wrote:'How many numbers up to 10,000 do you have to test to ensure that you have found all the primes?'
Well it seems to me that you have to test all the numbers up to 9973 to ensure that you have found them all. But how would you translate this into code?
Again, this seems to hint at the Sieve of Eratosthenes...
But I think you should answer the question with √n − 1 because 1 doesn't count as a prime number.Paul Clapham wrote: . . . If you use the Sieve of Eratosthenes then you don't need to test any numbers to see if they are prime. . . . There's basically no testing of any kind going on.
Paul Clapham wrote:The question is unclear, though.
S Connor wrote:
a)Write a method that determines whether a number is prime. (I can do this part.)
b)Use this method in an application that determines and displays all the prime numbers less than 10,000. How many numbers up to 10,000 do you have to test to ensure that you have found all the primes?
S Connor wrote:
Steve Fahlbusch wrote:Carey,
You are correct, but what i was trying to throw out there was once you got to sqrt 10000 you had done all of the checking you need to do globally.
Also, the outer loop only need to to iterate to 6n+1 > 10000.
and like you said, the inner loop (inside the isPrime function) only needs to iterate to sqrt n.
thanks for the clarification.
-steve
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |