fun distribute(num: Int): List<Int> {
var primeFactors: MutableList<Int> = mutableListOf()
var i = 2
var n = num
while (n > 1) {
if (n % i == 0) {
primeFactors.add(i)
n /= i
} else {
i++
}
}
return primeFactors
}
fun main() {
val n = 124
val result = distribute(n)
println("Czynniki pierwsze liczby $n: $result")
}
ZnVuIGRpc3RyaWJ1dGUobnVtOiBJbnQpOiBMaXN0PEludD4gewogIHZhciBwcmltZUZhY3RvcnM6IE11dGFibGVMaXN0PEludD4gPSBtdXRhYmxlTGlzdE9mKCkKICB2YXIgaSA9IDIKICB2YXIgbiA9IG51bQoKICB3aGlsZSAobiA+IDEpIHsKICAgIGlmIChuICUgaSA9PSAwKSB7CiAgICAgIHByaW1lRmFjdG9ycy5hZGQoaSkKICAgICAgbiAvPSBpCiAgICB9IGVsc2UgewogICAgICBpKysKICAgIH0KICB9CgogIHJldHVybiBwcmltZUZhY3RvcnMKfQoKZnVuIG1haW4oKSB7CiAgdmFsIG4gPSAxMjQKCiAgdmFsIHJlc3VsdCA9IGRpc3RyaWJ1dGUobikKCiAgcHJpbnRsbigiQ3p5bm5pa2kgcGllcndzemUgbGljemJ5ICRuOiAkcmVzdWx0IikKfQ==