Subscribe Us

Responsive Advertisement

Advertisement

Sieve algorith ,how to find prime number optimal way

Sieve algorith ,how to find prime number optimal way




#include<bits/stdc++.h>

using namespace std;

#define ll long long int

const ll N=10000009;

 vector<bool> isprime(N,1);

void sieve()

{


    isprime[0]=0;

    isprime[1]=0;

    for(ll i=2;i<N;i++)

     {


          if(isprime[i])

          {

              for(ll j=i*i;j<N;j+=i)

              {

                  isprime[j]=0;

              }

          }



      }

   for(ll i=0;i<30;i++)

   {

       if(isprime[i])cout<<i<<endl;

   }


}

int main()

{

  sieve();



    return 0;

}


Post a Comment

0 Comments