Prateek loves candy

where i am getting error in this ??

#include
#include
using namespace std;
#define ll long long
int main() {
ll pre[1000000];
int t;
cin>>t;
while(t–){
int n;
cin>>n;
memset(pre,1,sizeof(pre));

	for(ll i=2;i*i<=1000000;i+=2){
		if(pre[i]==1){
			for(ll j=i*i;j*j<=1000000;j+=i){
				pre[j]=0;
			}
		}
	}
	pre[0]=pre[1]=0;
	pre[2]=1;
	int ans=0,j=2;
	while(ans<=n){
		if(pre[j]==1){
			ans++;
		}
		j++;
	}
	cout<<pre[j];
}
return 0;

}

Hi,

while calculating sieve condition for second loop is for(int j=i*i;j<=1000000;j+=i)
Also precompute the ans upto 1000000 then print for each query.

can you please correct in the code what you are saying to do https://ide.codingblocks.com/s/197859

Coding blocks ide is under maintanence. please send it on another ide link.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.