jGuru Forums

Writing the testCases for Generating prime no. as early as possible, with explanation
1 posts in topic
Flat View
TOPIC ACTIONS:

Posted By:   vinod_kumar
Posted On:   Monday, April 16, 2007 01:19 PM

The algorith is 1)Write a list of numbers from 2 to the largest number you want to test for primality. Call this List A. 2)Write the number 2, the first prime number, in another list for primes found. Call this List B. 3)Strike off 2 and all multiples of 2 from List A. 4)The first remaining number in the list is a prime number. Write this number into List B. 5)Strike off this number and all multiples of this number from List A. The crossing-off of multiples can be started at the square of the number, as lower multiples have already been crossed out in previous steps. 6)Repeat steps 4 through 6 until no more numbers are left in List A.    More>>

The algorith is
1)Write a list of numbers from 2 to the largest number you want to test for primality. Call this List A.

2)Write the number 2, the first prime number, in another list for primes found. Call this List B.

3)Strike off 2 and all multiples of 2 from List A.

4)The first remaining number in the list is a prime number. Write this number into List B.

5)Strike off this number and all multiples of this number from List A. The crossing-off of multiples can be started at the square of the number, as lower multiples have already been crossed out in previous steps.

6)Repeat steps 4 through 6 until no more numbers are left in List A.

<<Less

Re: Writing the testCases for Generating prime no. as early as possible, with explanation

Posted By:   Robert_Lybarger
Posted On:   Monday, April 16, 2007 08:51 PM

Congratulations -- you've just explained the "sieve of erastothenes". So do you have a question to go along with that?