public static List<Integer> GetPrimes(int max) {
        boolean[] workingSet = new boolean[max + 1];
        for (int i = 2; i < workingSet.length; i++) {
            workingSet[i] = true;
        }
        int p = 2;
        while (p * p <= max) {
            int j = p * p;
            while (j <= max) {
                workingSet[j] = false;
                j = j + p;
            }
            p++;
            while (!workingSet[p]) {
                p++;
            }
        }

        ArrayList<Integer> primes = new ArrayList<Integer>();
        for (int i = 2; i < workingSet.length; i++) {
            if (workingSet[i]) {
                primes.add(i);
            }
        }
        return primes;
    }