题解 | #阶乘#
阶乘
https://www.nowcoder.com/practice/e58c8a55162d49c48115bdfa5da7da56
#include <iostream> using namespace std; int jc(int a) { if(a==0) { return 1; } else return a*jc(a-1); } int test01(int a) { int sum=0; int i; if(a%2==0) { i=2; } else { i=1; } for(;i<=a;i=i+2) { sum+=jc(i); } return sum; } int main() { int n; int p,q; while(cin>>n) { if(n%2==0) { q=n; p=n-1; } else { q=n-1; p=n; } cout<<test01(p)<<" "<<test01(q)<<endl; } } // 64 位输出请用 printf("%lld")