fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int arr[1003003], i, j;
  7. for(int k=0; k<1003003; k++) arr[k]=true;
  8. arr[0]=arr[1]=false;
  9. for(i=2; i*i<=1003003; i++) {
  10. if(!arr[i]) continue; //doesnt execute the inner loop if "i" is
  11. for(j=i*i; j<=1003003; j=j+i) { // false, or not prime
  12. arr[j]=false; //all multiples of "i" are assigned "false", or not prime
  13. }
  14. }
  15. return 0;
  16. }
Success #stdin #stdout 0.02s 7124KB
stdin
Standard input is empty
stdout
Standard output is empty