题解 | #尼科彻斯定理#
尼科彻斯定理
https://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85
let m = readline(); let arithMean = Math.pow(m,3) / m; let removeCount = 0; let startNum; let res = ''; let output = function (m) { for(let i = 0; i < m; i++) { if (i === m-1) { res += startNum; break; } res += startNum + '+'; startNum = startNum + 2; } console.log(res) } if (arithMean % 2 === 0) { // 等差中项是偶数 removeCount = m / 2; startNum = arithMean - 1 -(removeCount -1)*2; output(m); } else { // 等差中项是奇数 if (arithMean === 1) console.log(1); removeCount = (m-1)/2; startNum = arithMean - removeCount*2; output(m); }
#算法学习#