private static boolean isPrime(int val) {
    if (val % 2 == 0) return false;
    int maxDivisor = (int)Math.sqrt(val);
    for (int i = 3; i <= maxDivisor; i += 2) {
      if (val % i == 0) return false;
    }
    return true;
  }
private static boolean isPrime(int val)