Code example for TreeSet

Methods: add, size, toArray

0
 
public class Problem95 { 
    private static final Logger logger = Logger.getLogger(Problem95.class.getName());
 
    private static Integer[] amicableNumbers(int n, int MAX) {
        Set<Integer> set = new TreeSet<>();
        boolean complete = false;
        set.add(n);
        int summationOfDivisors = n;
        while (!complete) {
            summationOfDivisors = summation(properDivisors(summationOfDivisors));
            complete = (summationOfDivisors == n) || !set.add(summationOfDivisors) || summationOfDivisors >= MAX;
        } 
        return (summationOfDivisors == n) ? set.toArray(new Integer[set.size()]) : new Integer[0];
    } 
 
    public static int explore(int start, int MAX) {
        int[] chainLengths = new int[MAX + 1];
        int[] smallestInChain = new int[MAX + 1];
        chainLengths[1] = -1;
        for (int i = start; i < MAX; i++) {