通项公式:

an=a1+(n1)da_n = a_1 + (n - 1) d

n项和:

Sn=n(a1+an)/2S_n = n (a_1 + a_n) / 2

套用公式即可

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();
    }
}