题目:
题解:
m个连续奇数之和,所以我们只要求出连续奇数的第一位就能以此枚举所有奇数,连续奇数是一个等差数列。
S = m^3, n = m, d = 2 ===> a1 = m^2 - (m-1)
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int m = in.nextInt();
in.nextLine();
int sum = m * m * m;
int a1 = sum / m - (m-1);
StringBuffer sb = new StringBuffer();
sb.append(a1);
for (int i = 1; i < m; i++) {
a1+=2;
sb.append("+");
sb.append(a1);
}
System.out.println(sb.toString());
}
}
时间复杂度:O(n)