Prateek Loves Candy

it is not getting submitted … i mean no judgement is coming .
here is my code —
#include<bits/stdc++.h>
using namespace std;
// #define MAX 5000000
#define MAX 100000007
bool isPrime[MAX];
vectorans;

int sieveOfEratosthenes(int n){
isPrime[0]=false;
isPrime[1]=false;
// for(int i=0;i<=MAX;i++){
for(int i=2;i<MAX;i++){
isPrime[i]=true;
}
// for(int i=2;ii<=MAX;i++){
for(int i=2;i
i<MAX;i++){
if(isPrime[i]){
// ans.push_back(i);
for(int j=i*i;j<MAX;j+=i){
isPrime[j]=false;
}
}
}

for(int i=2;i<MAX;i++){
if(isPrime[i]){
ans.push_back(i);
}
}
return ans[n-1];
}
int main(){
int t;
cin>>t;
while(t–){
int n;
cin>>n;
cout<<sieveOfEratosthenes(n)<<endl;
}

return 0;

}

you are calliing sieve of eratosthesnes for every test case it will give you time limit exceed.
once you stored prime number in vector just print ans[n-1] for every test case it will give you nth prime number.
i have updated your code you can take it as refrence (https://ide.codingblocks.com/j/5844064e).
and one thing more in problem it states that answer can’t be more than 10^6 so MAX size will be 10^6.
as array size cant be 10^9 which you have taken.
if still you get some doubts please let me know

heyy if u still facing problems look through this one (https://ide.codingblocks.com/s/171242)

hey @avinashmallik2017,if you are still facing any problem or have any doubt please let me know else please mark this doubt as resolved,Thanxx.
regards,
devwrat

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.