Getting tle tried all approach

#include<bits/stdc++.h>

/---------------------------------- PRATHAMZX -----------------------------------/

typedef long long int ll;
#define pb push_back
#define pob pop_back
#define mk make_pair
#define fr first
#define sc second
#define pu push
#define ins insert
#define mod 1000000007
#define F(i,n) for(ll i=0;i<n;i++)
#define in(a,n) F(i,n) cin>>a[i]
#define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl;
#define pratham ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll a[90000000]={0};
void soe()
{
a[2]=1;
for(ll i=3;i<90000000;i=i+2)
{
a[i]=1;
}
for(ll i=3;i<90000000;i=i+2)
{
if(a[i]){
for(ll j=ii;j<90000000;j=j+2i)
{
a[j]=0;
}
}
}
}
int main(){
soe();
ll n;
cin>>n;
ll i=0;
while(n)
{
if(a[i])
{
n–;
}
i++;
}
cout<<i-1;
return 0;
}

hello @naaz
A) u r declaring quite large size sieve which might give mle or run error.
check value of 50 000th prime number and then declare ur sieve size just greater than that.
B)

this is time taking ,to make it efficient store first 50 000 th prime number in some vector and then use it to answer each query in o(1).

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.