题解 | #尼科彻斯定理#

尼科彻斯定理

https://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85?tpId=37&tqId=21299&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=2&judgeStatus=undefined&tags=&title=

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
    while ((line = await readline())) {
        let number = parseInt(line);
        let square = number * number;
        let array = [];
        if (number % 2 !== 0) {
            array.push(square);
            for (let i = 1; i <= number / 2; i++) {
                array.push(square - 2 * i);
                array.push(square + 2 * i);
            }
        } else {
            for (let i = 0; i < number / 2; i++) {
                array.push(square - 1 - 2 * i);
                array.push(square + 1 + 2 * i);
            }
        }
        array.sort((a,b)=>(a-b));
        console.log(array.join("+"));
    }
})();

全部评论

相关推荐

05-23 19:02
吉林大学 Java
点赞 评论 收藏
分享
群星之怒:不是哥们,你就不好奇瘫痪三十年的老植物人是啥样的吗?
点赞 评论 收藏
分享
这一集&nbsp;硕士输的很惨
找工作ing10:就是这样不是硕士不愿意脱下长衫,是人家觉得屈才了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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