题解 | #质数因子#

质数因子

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(' '))
    }
}()

全部评论

相关推荐

10-09 17:17
已编辑
门头沟学院 Java
活泼的代码渣渣在泡池...:同学你好,我也是学院本,后天要面这个亚信科技,是实习,请问问题都啥样呀,我项目就做了网上的,这是第一次面试
投递多益网络等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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