fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int zakres,j=1,k=2,m;
  8. cin>>zakres;
  9. int sito[zakres];
  10. //1-liczba pierwsza 2-niepierwsza
  11. for(int i=0; i<=zakres;i++)
  12. sito[i]=j++; //wypelnienie tablicy liczbami z zakresu(1,zakres)
  13.  
  14. for(int i=0; i<zakres; i++) cout<<sito[i]<<" ";
  15. cout<<endl;
  16. //zalozenie Killavusa - kazdy element tablicy=0
  17. for(int i=0; i<zakres; i++) sito[i]=0;
  18.  
  19. sito[0]=2;
  20.  
  21. for(int x=0; x<=zakres; x++)
  22. {
  23. if(sito[x]==0)sito[x]=1;
  24. int l=2;
  25. for(m=k; (m*l-1)<=zakres; l++)
  26. sito[m*l-1]=2;
  27. k=m;
  28. k++;
  29. }
  30.  
  31. for(int i=0; i<zakres; i++) cout<<sito[i]<<" ";
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 2900KB
stdin
50
stdout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 
2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2