标签:style blog java 2014 javascript cti
分解质因数算法var result = new Array(); var factor = function f(n){ if(n == 1){return ;} var n1 = n; while(n1>1){ if(isPrime(n1) && n % n1 == 0) {break;} n1--; } if(n1 == 1){return ;} result.push(n1); f(n / n1); } var isPrime = function (n){ for(var i = 2; i < n ; i++){if(n%i == 0){return false;}} return true; } factor(45); console.log(result);
标签:style blog java 2014 javascript cti
原文地址:http://blog.csdn.net/lan_liang/article/details/36671577