public List<Integer> soe(int S) { //S=population size.
        //Initialize array.
        List<Element> allNumbers = new LinkedList<Element>();
        //Populate with all numbers from 2 to S (inclusive).
        int i = 1;
        while (++i <= S) {
            allNumbers.add(new Element(i, false));
        }

        //Initialize p to the first prime number.
        int p=2;
        //Initialize m to first multiple second to 1.
        int m=2;
        int n=0; //Index of p.

        //Loop and mark.
        while (p <= Math.sqrt(S)) {
            while (m * p <= S) {
                Element e = allNumbers.get(m * p - 2); //2 subtracted to match with modified index numbers.
                e.setMarked(true);
                allNumbers.set(m * p - 2, e);
                m++;
            }
            while (allNumbers.get(++n).isMarked());
            p = allNumbers.get(n).getEle();
            m=2;
        }

        //Return non-marked numbers.
        List<Integer> returnList = new LinkedList<Integer>();
        for (int f=0; f<allNumbers.size(); f++) {
            if (!allNumbers.get(f).isMarked()) {
                returnList.add(allNumbers.get(f).getEle());
            }
        }

        return returnList;

    }