高中的我们看到这个题的一瞬间,一定会觉得这是个弱智题。然而现在的我,想了好久。。
题目的意思是已知等差数列和 为
,项数n为m,公差d为2,求首项
:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextInt()) {
int n = in.nextInt();
long sum = (long)Math.pow(n,3);
int a1 = (int)sum/n - (n - 1);
StringBuilder sb = new StringBuilder(Integer.toString(a1));
for(int i = 1; i < n; i++){
a1 = a1 + 2;
sb.append("+");
sb.append(a1);
}
System.out.println(sb);
}
}
}
京公网安备 11010502036488号