Prateek Loves Candy

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for (int i = 0 ; i < t ; i++){
int n = s.nextInt();
int last = 2 ;
int count = 1 ;
int j = 2 ;
while (count <= n){
int x = 0 ;
for (int k = 2 ; k < j ; k++){
if (j%k == 0){
x = 1 ;
break ;
}
}
if (x != 1){
last = j ;
count++ ;
}
j++ ;
}
System.out.println(last);
}
}
}
why the code is not getting submitted even after successful compilation ?

hey @Sejalrathi
u are getting tle because maximum value of t can be 10000

and for each test case u r running loop for 1000000 times due to which overall number of operations are 10000 X 1000000 which is greater than 10^8 .

to remove tle just store each prime numbers in an array or vector (say pr) and print pr[n-1] when u r asked to print nth prime

that is fine but atleast the code should get submitted.

@Sejalrathi correct your code and try to submit it.If it still does not submit you can mail to [email protected]