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?