题解 | #尼科彻斯定理#

尼科彻斯定理

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);
}

#算法学习#
全部评论

相关推荐

07-09 12:12
门头沟学院 Java
5月底投简历7月初开奖收获秋招第一个offer,虽然白菜价,但至少能保底了
土木转行ing:土木博士想转图像,最后拿了 tp 提前批 sp 最低档,感觉性价比不高
TP-LINK开奖132人在聊
点赞 评论 收藏
分享
不亏是提前批,神仙打架,鼠鼠不配了
站队站对牛:现在92都报工艺岗了
投递韶音科技等公司7个岗位
点赞 评论 收藏
分享
06-28 22:48
已编辑
广东金融学院 Java
小浪_Coding:学院本+这俩项目不是buff叠满了嘛
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务