How can I avoid this , can you please suggest me some way in which i can decrease time or make my code for efficient
Time limit error
Store all the primes upto 10^6 with the help of sieve and then for each query, just print the ith prime number. Time complexity - n log log n
sieve? i don’t much idea about time complexity as of now
Hey , I have applied the sieve algorithm but now it is showing time limit exceeded for all the test cases can you please review my code??
Please post the code.
I run it on my system its working fine but on coding blocks giving RUN ERROR
#include<bits/stdc++.h>
void sieve(int *p);
using namespace std;
int main()
{
int p[10000]={0};
sieve(p);
int test;
cin>>test;
while(test--)
{
int a;
cin>>a;
int i=0, count=0;
while(count!=a)
{
if(p[i]==1)
{
count++;
if(count==a)
cout<<i<<endl;
}
i++;
}
}
}
void sieve(int *p)
{
for(int i=3; i<10000; i=i+2)
p[i]=1;
for(int i=3; i<10000; i=i+2)
{
if(p[i]==1)
{
for(int j= i*i; j<10000; j= j+i)
p[j]=0;
}
}
p[0]=p[1]=0; p[2]=1;
}