@@ -0,0 +1,1396 @@
+package practice.mathematics;%0D%0A%0D%0Aimport java.util.ArrayList;%0D%0Aimport java.util.List;%0D%0Aimport java.util.Map;%0D%0Aimport java.util.Optional;%0D%0Aimport java.util.function.BinaryOperator;%0D%0A%0D%0Apublic class PerfectNumber %7B%0D%0A%0D%0A%09private PerfectNumber() %7B%7D%0D%0A%09%0D%0A%09public static List%3CInteger%3E getPerfectNumbers(int number) %7B%0D%0A%09%09List%3CInteger%3E perfectNumberList = new ArrayList%3C%3E();%0D%0A%09%09for (int i = 2; i %3C= number; i++) %7B%0D%0A%09%09%09if (isPerfectNumber(i)) %7B%0D%0A%09%09%09%09perfectNumberList.add(i);%0D%0A%09%09%09%7D%0D%0A%09%09%7D%0D%0A%09%09return perfectNumberList;%0D%0A%09%7D%0D%0A%09%0D%0A%09public static boolean isPerfectNumber(int number) %7B%0D%0A%09%09Map%3CInteger, Integer%3E primeFactorMap = PrimeFactorization.primeFactorize(number);%0D%0A%09%09List%3CInteger%3E toMultiply = new ArrayList%3C%3E();%0D%0A%09%09%0D%0A%09%09for (Integer k : primeFactorMap.keySet()) %7B%0D%0A%09%09%09int pow = 1;%0D%0A%09%09%09int sum = 1;%0D%0A%09%09%09%0D%0A%09%09%09for(int i = 0; i %3C primeFactorMap.get(k); i++) %7B%0D%0A%09%09%09%09pow *= k;%0D%0A%09%09%09%09sum += pow;%0D%0A%09%09%09%7D%0D%0A%09%09%09%0D%0A%09%09%09toMultiply.add(sum);%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09if (toMultiply.isEmpty()) %7B%0D%0A%09%09%09return false;%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09Optional%3CInteger%3E result = toMultiply.stream().reduce(new BinaryOperator%3CInteger%3E() %7B%0D%0A%09%09%09%0D%0A%09%09%09@Override%0D%0A%09%09%09public Integer apply(Integer arg0, Integer arg1) %7B%0D%0A%09%09%09%09return arg0 * arg1;%0D%0A%09%09%09%7D%0D%0A%09%09%7D);%0D%0A%09%09%0D%0A%09%09return result.get() == number * 2;%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void main(String%5B%5D args) %7B%0D%0A%09%09List%3CInteger%3E perfectNumbers = getPerfectNumbers(10_000);%0D%0A%09%09%0D%0A%09%09System.out.println(perfectNumbers.toString());%0D%0A%09%09%0D%0A%09%7D%0D%0A%7D%0D%0A

Add PerfectNumber