why is this exceeding a time limit ??
#include
#include
using namespace std;
typedef long long ll;
int main() {
bool a[5000000];
ll n;
cin>>n;
memset(a,1,sizeof(a));
for(ll p=2;p*p<=n;p++){
if(a[p]==true){
for(ll i=p*p;p<n;i+=p){
a[p]=false;
}
}
}
for(ll i=2;i<n;i++){
if(a[i]==true){
cout<<i<<" ";
}
}
return 0;
}