Everytime this error occurs
when i try to submit
runguard: warning: timelimit exceeded (wall time): aborting command runguard: warning: command terminated with signal 15
My code is
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
while (t-- > 0) {
int n = scanner.nextInt();
int[] primes = generatePrimes(n);
int cost = primes[n - 1]; // Minimum cost is the nth prime number
System.out.println(cost);
}
scanner.close();
}
// Function to generate the first n prime numbers
private static int[] generatePrimes(int n) {
int[] primes = new int[n];
int count = 0;
int num = 2;
while (count < n) {
if (isPrime(num)) {
primes[count] = num;
count++;
}
num++;
}
return primes;
}
// Function to check if a number is prime
private static boolean isPrime(int num) {
if (num <= 1) {
return false;
}
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
return false;
}
}
return true;
}
}