题解 | #完全数计算#

完全数计算

https://www.nowcoder.com/practice/7299c12e6abb437c87ad3e712383ff84

const rl = require("readline").createInterface({ input: process.stdin });

rl.on('line',line => {
    const n = parseInt(line)
    let count = 0
    for(let i = 1;i <= n;i++) {
        let sum = 0
        for(let j = 1;j < Math.pow(i,1/2);j++) {
            if(i % j === 0){
                sum += j
                sum += i / j
            }
        }
        if(i === sum - i) ++count
    }
    console.log(count)
})

简单易懂

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务