Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on how the divisors are partitioned, only that the two partition sums are equal.



E.G.
 6 is a Zumkeller number; The divisors {1 2 3 6} can be partitioned into two groups {1 2 3} and {6} that both sum to 6.
 10 is not a Zumkeller number; The divisors {1 2 5 10} can not be partitioned into two groups in any way that will both sum to the same value.
 12 is a Zumkeller number; The divisors {1 2 3 4 6 12} can be partitioned into two groups {1 3 4 6} and {2 12} that both sum to 14.


Even Zumkeller numbers are common; odd Zumkeller numbers are much less so. For values below 10^6, there is at least one Zumkeller number in every 12 consecutive integers, and the vast majority of them are even. The odd Zumkeller numbers are very similar to the list from the task Abundant odd numbers; they are nearly the same except for the further restriction that the abundance (A(n) = sigma(n) - 2n), must be even: A(n) mod 2 == 0



Task

 Write a routine (function, procedure, whatever) to find Zumkeller numbers.
 Use the routine to find and display here, on this page, the first 220 Zumkeller numbers.
 Use the routine to find and display here, on this page, the first 40 odd Zumkeller numbers.
 Optional, stretch goal: Use the routine to find and display here, on this page, the first 40 odd Zumkeller numbers that don't end with 5.


See Also

 OEIS:A083207 - Zumkeller numbers to get an impression of different partitions OEIS:A083206 Zumkeller partitions
 OEIS:A174865 - Odd Zumkeller numbers


Related Tasks

 Abundant odd numbers
 Abundant, deficient and perfect number classifications
 Proper divisors , Factors of an integer
import java.util.ArrayList
import kotlin.math.sqrt
 
object ZumkellerNumbers {
    @JvmStatic
    fun main(args: Array<String>) {
        var n = 1
        println("First 220 Zumkeller numbers:")
        run {
            var count = 1
            while (count <= 220) {
                if (isZumkeller(n)) {
                    print("%3d  ".format(n))
                    if (count % 20 == 0) {
                        println()
                    }
                    count++
                }
                n += 1
            }
        }
 
        n = 1
        println("\nFirst 40 odd Zumkeller numbers:")
        run {
            var count = 1
            while (count <= 40) {
                if (isZumkeller(n)) {
                    print("%6d".format(n))
                    if (count % 10 == 0) {
                        println()
                    }
                    count++
                }
                n += 2
            }
        }
 
        n = 1
        println("\nFirst 40 odd Zumkeller numbers that do not end in a 5:")
        var count = 1
        while (count <= 40) {
            if (n % 5 != 0 && isZumkeller(n)) {
                print("%8d".format(n))
                if (count % 10 == 0) {
                    println()
                }
                count++
            }
            n += 2
        }
    }
 
    private fun isZumkeller(n: Int): Boolean { //  numbers congruent to 6 or 12 modulo 18 are Zumkeller numbers
        if (n % 18 == 6 || n % 18 == 12) {
            return true
        }
        val divisors = getDivisors(n)
        val divisorSum = divisors.stream().mapToInt { i: Int? -> i!! }.sum()
        //  divisor sum cannot be odd
        if (divisorSum % 2 == 1) {
            return false
        }
        // numbers where n is odd and the abundance is even are Zumkeller numbers
        val abundance = divisorSum - 2 * n
        if (n % 2 == 1 && abundance > 0 && abundance % 2 == 0) {
            return true
        }
        divisors.sort()
        val j = divisors.size - 1
        val sum = divisorSum / 2
        //  Largest divisor larger than sum - then cannot partition and not Zumkeller number
        return if (divisors[j] > sum) false else canPartition(j, divisors, sum, IntArray(2))
    }
 
    private fun canPartition(j: Int, divisors: List<Int>, sum: Int, buckets: IntArray): Boolean {
        if (j < 0) {
            return true
        }
        for (i in 0..1) {
            if (buckets[i] + divisors[j] <= sum) {
                buckets[i] += divisors[j]
                if (canPartition(j - 1, divisors, sum, buckets)) {
                    return true
                }
                buckets[i] -= divisors[j]
            }
            if (buckets[i] == 0) {
                break
            }
        }
        return false
    }
 
    private fun getDivisors(number: Int): MutableList<Int> {
        val divisors: MutableList<Int> = ArrayList()
        val sqrt = sqrt(number.toDouble()).toLong()
        for (i in 1..sqrt) {
            if (number % i == 0L) {
                divisors.add(i.toInt())
                val div = (number / i).toInt()
                if (div.toLong() != i) {
                    divisors.add(div)
                }
            }
        }
        return divisors
    }
}