public static List<Integer> sieveOfEratosthenes(int n) {
        int offset = 2;
        boolean[] sieve = new boolean[n-offset];
        int p = 2;
        do{
            for (int j = 2; p*j < n; j++) {
                sieve[p*j-offset] = true;
            }
            int i = 0;
            for (i = 0; i < sieve.length; i++) {
                if(!sieve[i]&&i+offset>p){
                    p = i+offset;
                    break;
                }
            }
            if(i==sieve.length&&p!=i+offset){
                break;
            }
        }while(p<n);
        ArrayList<Integer> array = new ArrayList<>();
        for (int i = 0; i < sieve.length; i++) {
            if(!sieve[i]){
                array.add(i+offset);
            }
        }
        return array;
    }