题解 | #质数因子#

质数因子

https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607

// 1.质因子为质数
// 2.n的质因子范围为 2 <= x <= 根号n
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    while(line = await readline()){
        let num = parseInt(line)
        const list = []
        for(let i = 2; Math.pow(i, 2) <= num; i++) {
            while(num % i === 0) {
                list.push(i)
                num /= i
            }
        }
        if (num > 1) {
            list.push(num)
        }
        console.log(list.join(' '))
    }
}()

全部评论

相关推荐

大四三本软工专业感觉寄了,沟通700+才投出去简历20多
啊咿唔:太面向工作写简历,比如说分布式锁这种,以及项目里的minio,架构写vue nginx都很暴露水平
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务