AmanFTW's blog

By AmanFTW, history, 17 months ago, In English

int maxx = 1e5; vector prime; prime.resize(maxx); for(int i =1;i<maxx;i++){ prime[i]=1; } for(int i =2;i<maxx;i++){ if(prime[i]==1){ for(int j =i;j<maxx;j+=i){ prime[j]=0; } } }

  • Vote: I like it
  • -30
  • Vote: I do not like it

»
17 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

Second loop should not start from i. Otherwise everything will be marked as false. Start with i*i or 2*i.