这个还是很好玩的一道简单水题咯..呵呵
#include <stdio.h> #include <string.h> #include <math.h> #include <iostream> #include <string> #include <algorithm> using namespace std; int fun (int x) { if (x <= 0) return 1; //主要是这里 不要返回0,要返回1 if (x == 1) return 1; return x % 2 == 0 ? (x - 1) * fun (x - 1 - 2) : x * fun (x - 2); //这里也是用的递归求解 } int main () { int N; cin >> N; while (N--) { int x; cin >> x; int sum = 0; for (int i = 1; i <= x; i++) { sum += fun (i); } cout << sum << endl; } return 0; }