public static List<Long> GetLongPrimesList(long max) {
        HashSet<Long> workingSet = new HashSet<Long>();
        for (long i = 2; i < max + 1; i++) {
            workingSet.add(i);
        }
        long p = 2;
        while (p * p <= max) {
            long j = p * p;
            while (j <= max) {
                workingSet.remove(j);
                j = j + p;
            }
            p++;
            while (!workingSet.contains(p)) {
                p++;
            }
        }

        List<Long> primes = new LinkedList<Long>();
        for (long i = 2; i < max + 1; i++) {
            if (workingSet.contains(i)) {
                primes.add(i);
            }
        }
        return primes;
    }