题解 | #质数因子#
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
首先,只需遍历到,但遍历完后还没完,比如10这个数字,10的平方根是3.几,但它的质数因子是2、5,所以遍历到根号10后,还剩下10/2=5,则剩下的这个,如果不是1,则必定也是质数,再把它放进去即可。
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 res = []; let n = parseInt(line); let tmp = n; for (let i = 2; i*i <= n; i++) { while(tmp%i==0){ res.push(i); tmp /= i; } } if(tmp != 1){ res.push(tmp); } console.log(res.join(' ')); } })();