题解 | #质数因子#

质数因子

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

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
    let num = 0;
    while(line = await readline()){
       num = parseInt(line);
    }
    let result = [];
    let i=2;
    while(i<=num && i * i <= num){

    // for(let i=2; i<=num; i++){
        while(num%i===0 && num!==i){
            result.push(i);
            num = num/i;
        }
        ++i;
        //  if(num == i){
        //     result.push(i);
        //     break
        // }
    }
    if(num !=1){
        result.push(num)
    }
    console.log(result.join(" "))
    return result.join(" ");
}()

全部评论

相关推荐

点赞 评论 收藏
分享
喜欢走神的孤勇者练习时长两年半:爱华,信华,等华,黑华
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务