题解 | #尼科彻斯定理#
尼科彻斯定理
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 n = sc.nextInt();
if(n%2==0){
int count = n/2-1;
int sNum = n*n-1-count*2;
System.out.print(sNum);
for(int i =0;i<n-1;i++){
sNum += 2;
System.out.print("+"+sNum);
}
}
else{
int count = n/2;
int tNum = n*n-count*2;
System.out.print(tNum);
for(int i = 0;i<n-1;i++){
tNum += 2;
System.out.print("+"+tNum);
}
}
}
}
分一下奇数偶数的情况,发现n^2等于数列中位数