All Downloads are FREE. Search and download functionalities are using the official Maven repository.

g0501_0600.s0507_perfect_number.Solution.kt Maven / Gradle / Ivy

There is a newer version: 1.30
Show newest version
package g0501_0600.s0507_perfect_number

// #Easy #Math #2023_01_06_Time_172_ms_(81.82%)_Space_34.1_MB_(18.18%)

class Solution {
    fun checkPerfectNumber(num: Int): Boolean {
        var s = 1
        for (sq in Math.sqrt(num.toDouble()).toInt() downTo 2) {
            if (num % sq == 0) {
                s += sq + num / sq
            }
        }
        return num != 1 && s == num
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy