doubt in sieve in linear time

Revision en1, by Aden_blizzard, 2021-02-07 09:05:46

const int N = 10000000; int lp[N+1]; vector pr;

for (int i=2; i<=N; ++i) { if (lp[i] == 0) { lp[i] = i; pr.push_back (i); } for (int j=0; j<(int)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j) lp[i * pr[j]] = pr[j]; } in this code for sieve in linear time complexity what is the use of pr[j]<=lp[i]? is there any reason to write this as i tried many test case but it works fine without this ....is there any case where it fails?

Tags sieve

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Aden_blizzard 2021-02-07 09:06:31 281
en1 English Aden_blizzard 2021-02-07 09:05:46 510 Initial revision (published)