题解 | #等差数列#
等差数列
https://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
#include <iostream> using namespace std; //求前n项和 int sum(const int n) { //递归出口 if (n == 1) return 2; //前(n-1)项+第n项 return sum(n - 1) + 3 * n - 1; } int main() { int n; while (cin >> n) { // 注意 while 处理多个 case cout << sum(n) << endl; } } // 64 位输出请用 printf("%lld")