Prateek loves candy problem error

#include
using namespace std;

int main() {
int t, n, count, i, c=3;
cin>>t;
while(t–) {
cin>>n;
if(n==1) {
cout<<“2”<<"\n";
}
else if(n>1) {
for(count=2;count<=n;c++) {
for(i=2;i<c;i++) {
if(c%i==0)
break;
}
if(c==i)
count++;
}
cout<<i<<"\n";
}
}
return 0;
}

Time limit exceeded error. Please help.

hey shivani, you have to solve this question using sieve of eratosthenes

Hi Nitin, please try this question with the help of Sieve of Eratosthenes. Then find the the nth prime number.

Hi Shivani, as you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.