题解 | #查找组成一个偶数最接近的两个素数#
查找组成一个偶数最接近的两个素数
https://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
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 const isSu = (x) => { // 判断是否为素数 for(let i=2;i<x;i++){ if(x%i===0)return false; } return true; }; while ((line = await readline())) { let number = parseInt(line); let middle = number / 2; let a=middle; let b=middle; if(middle===2){ a=2; b=2; } else{ while(a!==2){ if(isSu(a)&&isSu(b))break; else{ a--; b++; } } } console.log(a); console.log(b); } })();