private int sumFactors(int num) {
int sum = 0;
for (int i = 1; i <= num / 2; i++) {
if (num % i == 0) {
sum += i;
}
}
return sum;
}
public List<List<Integer>> findAmicableNumbers(int n) {
List<List<Integer>> res = new ArrayList<>();
int[] arr = new int[n];
for (int i = 2; i < n; i++) {
arr[i] = sumFactors(i);
}
for (int i = 0; i < n; i++) {
int j = arr[i];
if (j < i && i == arr[j]) {
res.add(Arrays.asList(i, j));
}
}
return res;
}
public static void main(String[] args) {
S_amicableNumberLessThanN sol = new S_amicableNumberLessThanN();
int n = 1000;
System.out.println(sol.findAmicableNumbers(n));
}