AC代码:
#include <iostream> #include <cstdio> using namespace std; int main(void) { freopen("in.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF) { long long int sum , sum1 = 0, sum2 = 1; if(n==1) sum=sum1; else if(n==2) sum=sum2; for(int i=3;i<=n;i++) { sum=(i-1)*sum1+(i-1)*sum2; sum1 = sum2; sum2 = sum; } printf("%lld ",sum); } fclose(stdin); system("pause"); return 0; }