Prateek Loves Candy || Prime numbers print

Prateek recently graduated from college. To celebrate, he went to a candy shop and bought all the candies. The total cost was a number upto which there are n prime numbers (starting from 2). Since Prateek wants to minimize his cost, he calls you to help him find the minimum amount that needs to be paid. Being a student of Prateek bhaiya it is now your job to help him out :slight_smile: Input Format First line contains a single integer denoting the number of test cases T. Next T lines contains a single integer N, denoting the number of primes required. Constraints T <= 10000 It is guaranteed that the answer does not exceed 10^6.

My code:

import java.util.;
public class Main {
public static void main(String args[]) {
Scanner scn=new Scanner(;
int t=scn.nextInt();
int n=scn.nextInt();
int count=0;
int i=2;
public static boolean checkprime(int n){
for(int i=2;i
return false;
return true;

Issue: TLE Just for 1 case. May be because of Large input. Can you help me with Use Sieve of Eratosthenes for this problem. Help!