Sàng nguyên tố Eratosthenes
// sang nguyen to
#include<bits/stdc++.h>
using namespace std;
vector<int> sang(int n){
bool s[n+5]={};
fill(s+2, s+n+1, true); // s2=...=sn=true
vector<int> P;
for(int i=2; i<=n; i++){
if(s[i] == true){
P.push_back(i);
for(int j=i*i;j<=n;j+=i) s[j] = 0;
}
}
return P;
}
int main(){
vector<int> P=sang(1000);
for(auto p:P) cout<<p<<" ";
}