题解 | #等差数列#
等差数列
http://www.nowcoder.com/practice/f792cb014ed0474fb8f53389e7d9c07f
int d(int n) { int sum = 2; int ret = sum; while (n-1) { sum = 2; sum += (n-1) * 3; ret += sum; n--; } return ret; } int main() { int n = 0; while (~scanf("%d", &n)) { printf("%d\n", d(n)); } return 0; }