class Euler58 {

    private static class Options {
        int thresholdPercent = 10;
        boolean runCheckpoints = true;
    }

    private static boolean parseIntAfterPrefix(String arg, String prefix, Options options) {
        if (!arg.startsWith(prefix)) {
            return false;
        }
        String tail = arg.substring(prefix.length());
        if (tail.isEmpty()) {
            return false;
        }

        int parsed = 0;
        for (int i = 0; i < tail.length(); i++) {
            char c = tail.charAt(i);
            if (c < '0' || c > '9') {
                return false;
            }
            parsed = parsed * 10 + (c - '0');
        }
        options.thresholdPercent = parsed;
        return true;
    }

    private static boolean parseArguments(String[] args, Options options) {
        for (String arg : args) {
            if ("--skip-checkpoints".equals(arg)) {
                options.runCheckpoints = false;
                continue;
            }
            if (parseIntAfterPrefix(arg, "--threshold-percent=", options)) {
                continue;
            }
            System.err.println("Unknown argument: " + arg);
            return false;
        }
        return options.thresholdPercent >= 1 && options.thresholdPercent <= 100;
    }

    private static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        }
        if ((n % 2) == 0) {
            return n == 2;
        }
        for (long p = 3; p <= n / p; p += 2) {
            if ((n % p) == 0) {
                return false;
            }
        }
        return true;
    }

    private static int solve(int thresholdPercent) {
        long primeCount = 0;
        long diagonalCount = 1;

        for (int layer = 1; ; ++layer) {
            long side = 2L * layer + 1L;
            long square = side * side;
            long step = side - 1;

            if (isPrime(square - step)) {
                ++primeCount;
            }
            if (isPrime(square - 2 * step)) {
                ++primeCount;
            }
            if (isPrime(square - 3 * step)) {
                ++primeCount;
            }

            diagonalCount += 4;

            if (primeCount * 100 < diagonalCount * thresholdPercent) {
                return (int) side;
            }
        }
    }

    private static boolean runCheckpoints() {
        if (solve(62) != 3) {
            System.err.println("Checkpoint failed for threshold 62%");
            return false;
        }
        if (solve(60) != 5) {
            System.err.println("Checkpoint failed for threshold 60%");
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Options options = new Options();
        if (!parseArguments(args, options)) {
            System.exit(1);
        }
        if (options.runCheckpoints && !runCheckpoints()) {
            System.exit(2);
        }

        System.out.println(solve(options.thresholdPercent));
    }
}
