[algogeeks] Re: prime number using Sieve of Eratosthenes

2011-03-21 Thread rohit
i just want to know , when we make a program how update array after deleting alternate element. On Mar 21, 4:37 pm, Anurag atri anu.anurag@gmail.com wrote: what did you not understand in this ? On Mon, Mar 21, 2011 at 4:59 PM, rohit scofiel...@rediffmail.com wrote: genrate prime number

Re: [algogeeks] Re: prime number using Sieve of Eratosthenes

2011-03-21 Thread abhijith reddy
cont int MAX = 10005; bool isPrime[MAX]; void sieve() { int lim=sqrt(MAX); /* Initially Mark all numbers as Prime */ for(int i=2;iMAX;i++) isPrime[i]=1; for(int i=2;i=lim;i++) if(isPrime[i])/* for each Prime */ for(int j=2*i;jMAX;j+=i)/* Cross

Re: [algogeeks] Re: prime number using Sieve of Eratosthenes

2011-03-21 Thread Anurag atri
take an array and put 0 at all positions in it (except 2 ) , then when you mark a number as a multiple of a prime number ( 2 to start with ) put 1 in that place ..then look for the first number in the array that has a 1 ( this time 3 ) do the same procedure again . On Mon, Mar 21, 2011 at 5:41

Re: [algogeeks] Re: prime number using Sieve of Eratosthenes

2011-03-21 Thread Anurag atri
better explained by Reddy's program :) On Mon, Mar 21, 2011 at 6:00 PM, Anurag atri anu.anurag@gmail.comwrote: take an array and put 0 at all positions in it (except 2 ) , then when you mark a number as a multiple of a prime number ( 2 to start with ) put 1 in that place ..then look for

[algogeeks] Re: prime number using Sieve of Eratosthenes

2011-03-21 Thread bittu
@allWhy Not Try Carziest Thing in This Question Q.1st Prrove Timpe Complexity of Sieve of Eratosthenes is O(Log(Log(n))) ..isn't Making U Stuck..?? Q.2nd We Need to Drease the same Number of element sieved more then one time e.g 6,12 all the multiples of 2,3 ..then again all the

Re: [algogeeks] Re: prime number using Sieve of Eratosthenes

2011-03-21 Thread sanchit mittal
hav a look at dis one...prime no upto 10 #define N 10 bool mark [N]; memset (mark, true, sizeof (mark)); mark [0] = mark [1] = false; for ( int i = 4; i N; i += 2 ) mark [i] = false; for ( int i = 3; i * i = N; i += 2 ) { if ( mark [i] ) { for ( int j = i *