题解 | #等差数列#
等差数列
https://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a1 = 2; int d = 3; //An = a1+(n-1)d = Am+(n-m)d //Sn = n*a1+n(n-1)d/2 = n(a1+an)/2 int sn = n*a1 + n*(n-1)*d/2; System.out.println(sn); } }