online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static List<Long> sieveOfEratosthenes(int limit) { boolean[] sieve = new boolean[limit + 1]; List<Long> primes = new ArrayList<>(); for (int i = 2; i <= limit; i++) { if (!sieve[i]) { primes.add((long) i); for (int j = i * i; j <= limit && j >= 0; j += i) { sieve[j] = true; } } } return primes; } public static long nthPrime(int n) { // Assuming the limit for generating primes // is greater than the nth prime number int limit = Math.max(n * 20, 100); // Adjust the minimum limit to avoid small sizes List<Long> primes = sieveOfEratosthenes(limit); return primes.get(n - 1); // n-1 because the list is 0-indexed } public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int a0 = 0; a0 < t; a0++) { int n = in.nextInt(); System.out.println(nthPrime(n)); } } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue