题解 | #等差数列#
等差数列
http://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
通项公式:
前n项和:
套用公式即可
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int length = sc.nextInt(); // n
int first = 2, last = 3 * length - 1; // a1, an
System.out.println((first + last) * length / 2);
}
sc.close();
}
}