题解 | #尼科彻斯定理#

尼科彻斯定理

https://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();

        int add = getAdd(num - 1);
        int start = add * 2 + 1;
        for (int i = 0; i < num; i++) {
            System.out.print(start);
            start += 2;
            if (i != num - 1) System.out.print("+");
        }
    }

    private static int getAdd(int i) {
        int res = 0;
        while (i > 0) {
            res = res + i;
            i--;
        }
        return res;
    }


}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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