题解 | #阶乘#
阶乘
https://www.nowcoder.com/practice/e58c8a55162d49c48115bdfa5da7da56
#include <iostream> using namespace std; long long factorial(int n) { long long res = 1; for (int i = 0, j = 1; i < n; ++i, ++j) { res = res * j; } return res; } int main() { int n; while (cin >> n) { long long y1 = 0, y2 = 0; for (int i = 1; i <= n ; i += 2) { //求y1 y1 += factorial(i); } for (int i = 2; i <= n ; i += 2) { //求y2 y2 += factorial(i); } cout << y1 << " " << y2 << endl; } }