题解 | #质数因子#

质数因子

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

全部评论

相关推荐

05-19 19:54
已编辑
杭州电子科技大学 Java
程序员小白条:《备考软考软件设计师》中级很简单的,不需要花很多时间,除非考软高,这简历找找杭州本地中小厂吧,也很难,项目这块还是最好有自己开发的思考,不要网上的亮点搬过来就行,看运气,本地有优势
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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