This is Discussion thread about Prateek Loves Candy
Discussion About Prateek Loves Candy
can their be more number of test cases
TLE is showing how to show
import java.util.;
public class Main {
static int max=1000005;
static ArrayList prime=new ArrayList();
public static void es(int k){
boolean[] isprime=new boolean[max];
for(int i=0;i<max;i++)
isprime[i]=true;
for(int p=2;pp<max;p++){
if(isprime[p]==true){
for(int i=p*p;i<max;i+=p)
isprime[i]=false;
}
}
for(int p=2;p<max;p++){
if(isprime[p]==true)
prime.add§;}
System.out.println(prime.get(k));
}
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int y=0;y<t;y++){
int k=sc.nextInt();
es(k); }
}
}
#include
using namespace std;
int arr[1000000]={0};
void isprime()
{
long long int i,j;
for(i=3;i<=1000000;i=i+2)
{
arr[i]=1;
}
for(i=3;i<=1000000;i=i+2)
{
for(j=i*i;j<=1000000;j=j+i)
{
arr[j]=0;
}
}
arr[0]=arr[1]=0;
arr[2]=1;
}
int main()
{
int t,i,j,n,k;
cin>>t;
for(i=0;i<t;i++)
{
cin>>n;
j=0;
isprime();
k=0;
while(j<n)
{
if(arr[k]==1)
{
j++;
}
k++;
}
cout<<k-1<<endl;
}
}
this is my code I am getting TLE please suggest changes