PHP调试太麻烦,给你个JS吧,反正也没悬赏,自己改一下就行了。//求出大于2的数字以内的全部质数
function getPrime(n) {
if (n
var values = [2];
if (n
var isPrime = function(num, primes) {
for (var i=0,l=primes.length; i
if (num % primes[i]
}
return true;
};
for(var i = 3; i <= n; i += 2) {
if (isPrime(i, values)) values.push(i);
}
return values;
}
var num = 15;
var primes = getPrime(num);
var groups = {};
for (var x=0, y=0, z=0, l=primes.length; x
var v = primes[x] + primes[y] + primes[z];
if (v == num) {
var g = [primes[x], primes[y], primes[z]];
g.sort(function(a, b){return a - b;}); //排序
var key = g.join('-');
if (! groups[key]) groups[key] = g; //防重复
}
if (v
z++;
} else {
z = l;
}
if (z == l) {
z = 0; y ++;
}
if (y == l) {
y = 0; x ++;
}
}
groups;//你要的js执行结果
Object { 2-2-11=[3], 3-5-7=[3], 5-5-5=[3]}