题解 | #尼科彻斯定理#
尼科彻斯定理
http://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85
package com.company.niuke;
import java.util.Scanner;
/**
* @ProjectName: leetcode
* @Package: com.company.niuke
* @ClassName: NicoChester
* @Author: Administrator
* @Description: 尼科彻斯定理
* @Date: 2022/2/16 22:51
* @Version: 1.0
*/
public class NicoChester {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int m = scanner.nextInt();
StringBuilder builder = new StringBuilder();
int cube = (int) Math.pow(m, 3);
for (int i = 0; i < m; i++) { //减掉奇数之间的差值
cube -= 2 * i;
}
int first = cube / m; //求出第一个数 理解为解方程式
for (int i = 0; i < m - 1; i++) {
builder.append(first+2*i).append("+");
}
System.out.println(builder.append(first + 2 * (m - 1)));
}
}
}