Weird Runtime error!

Revision en3, by shank_punk, 2015-10-03 00:57:49

Hi guys. I tried implementing sieve today (I have done it 50+ times before), and my code was giving Runtime error :(

I tried to find out the error in my code but I don't know what is wrong.


#include<bits/stdc++.h> using namespace std; bool vis[1000002]; int main(){ int i,j; for(i=2;i<=100000;i++) vis[i]=true; for(i=2;i<=100000;i++){ if(!vis[i]) continue; for(j=i*i;j<=100000;j+=i){ vis[j]=false; } //cerr<<i<<" "; } return 0; }

If I change j+=i to j++, it does not show runtime error!(& the code will obviously be wrong & TLE)

UPDATE : Found my mistake(updated in comment section).

Tags error, runtime error, dont downvote for fun

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English shank_punk 2015-10-03 00:57:49 69
en2 English shank_punk 2015-10-02 16:18:44 103 (published)
en1 English shank_punk 2015-10-02 16:15:57 525 Initial revision (saved to drafts)