Advertisement
Visher

Untitled

Jan 6th, 2012
4,841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. int numer = 0;
  2. int dzielnik = 2;
  3. vector <int> sito(1, 2); // Pierwszy domyślny element w sicie - liczba 2
  4.  
  5. // Wypelniamy zbior liczbami od 2 do liczba
  6. for (int x = 3; x <= liczba; x++)
  7.     sito.push_back(x);
  8.  
  9. // Usuwanie liczb nie-pierwszych | Pierw dzielniki liczby 2, potem liczby 3, (czworka po drodze odpadla), 5..
  10. do
  11. {  
  12.     for (int x = 2; x < sito.size(); x++)
  13.         if (sito[x] % dzielnik == 0)
  14.             sito.erase(sito.begin()+x);
  15.            
  16.     dzielnik = sito[numer++];
  17. }
  18. while (dzielnik != sito.back());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement