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 {