Prateek Loves Candy - TLE even after Sieve of erathosthenes

//Can anyone please tell me whats wrong in this, Iam getting TLE, even though I have used seive of //erathothenes
//Below is the code i have written-

#include <bits/stdc++.h>
using namespace std;

void SieveOfEratosthenes(int n)
{

bool prime[n+1];
memset(prime, true, sizeof(prime));

for (int p=2; p*p<=n; p++)
{

    if (prime[p] == true)
    {

        for (int i=p*p; i<=n; i += p)
            prime[i] = false;
    }
}


int p,c = 0;
for (p=2; p<=n; p++)
   {
       if (prime[p])
      //cout << p << " ";
      {
          c++;
          if(c == (n/3))
          {
              cout<<p<<endl;
              break;
          }
      }
   }

}

int main(){
int tt;
cin>>tt;
for(int m=0;m<tt;m++)
{

         int n;
         cin>>n;
         SieveOfEratosthenes(n*3);

}


 return 0;

}

Hey can you share the ide link of your code. And you are getting TLE because you are constructing sieve for each test case, you are supposed to create sieve once and then use it for every test case.

That’s because you are calling seive function again and again in while loop for T test cases.
So instead of this you can call the seive function only once and save the prime numbers in a vector and output v[n-1]th prime number.

https://ide.codingblocks.com/s/52605 like this.