fun isPerfect(n: Int): Boolean {
var sum = 0
for (i in 1 until n) {
if (n % i == 0) {
sum += i
}
}
return sum == n
}
fun main() {
val n = 6
val result = isPerfect(n)
if (result) {
println("$n jest liczba doskonala")
} else {
println("$n nie jest liczba doskonala")
}
}
ZnVuIGlzUGVyZmVjdChuOiBJbnQpOiBCb29sZWFuIHsKICB2YXIgc3VtID0gMAoKICBmb3IgKGkgaW4gMSB1bnRpbCBuKSB7CiAgICBpZiAobiAlIGkgPT0gMCkgewogICAgICBzdW0gKz0gaQogICAgfQogIH0KCiAgcmV0dXJuIHN1bSA9PSBuCn0KCmZ1biBtYWluKCkgewogIHZhbCBuID0gNgoKICB2YWwgcmVzdWx0ID0gaXNQZXJmZWN0KG4pCgogIGlmIChyZXN1bHQpIHsKICAgIHByaW50bG4oIiRuIGplc3QgbGljemJhIGRvc2tvbmFsYSIpCiAgfSBlbHNlIHsKICAgIHByaW50bG4oIiRuIG5pZSBqZXN0IGxpY3piYSBkb3Nrb25hbGEiKQogIH0KfQ==