其他分享
首页 > 其他分享> > Number质数

Number质数

作者:互联网

const number = 180;

let arr = [];
let flag = true;

getPrime(number);

print(arr.join(' '));

function getPrime(num) {
    if (num === 1) {
        return null;
    }
   for (let i = 2; i <= num/i; i++) {
       if (Math.ceil(num/i) === num/i){
           arr.push(i);
           getPrime(num/i);
           flag = false;
           break;
       }
     }
    if (flag) {
        arr.push(num);
    }
}
  

  

标签:arr,质数,Number,number,num,let,getPrime
来源: https://www.cnblogs.com/lizzy-yang/p/15916433.html