题解 | #查找组成一个偶数最接近的两个素数#
查找组成一个偶数最接近的两个素数
http://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
while(line = readline()) {
let num = parseInt(line);
let diff = 9999999999;
for(let start=1; start <= num/2; start++) {
for (let end=Math.floor(num/2); end < num; end++) {
if (start + end == num && isZhi(end) && isZhi(start)) {
if (end - start < diff ) {
diff = end - start;
}
}
}
}
let x = (diff + num) / 2;
let y = (num - diff) / 2;
print(y+'\n'+x)
function isZhi(count) {
let status = true;
for (let i=2; i<=count/2; i++) {
if (count%i == 0) {
status = false;
}
}
return status;
}
}