代码:
#include<iostream> #include<algorithm> #include<string.h> using namespace std; char a[102]={0},b[102][10000]; int k=2; void js(int x) { int cx=0,cb=0,i,j,t[3],s[10000]={0}; cb=strlen(b[k]); if (x/10==0) { t[0]=x; cx=1; } else if (x/100==0) { t[0]=x/10; t[1]=x%10; cx=2; } else { t[0]=x/100; t[1]=x/10%10; t[2]=x%10; cx=3; } for (i=0;i<cb;i++) for (j=0;j<cx;j++) { s[i+j+1]+=(b[k][i]-'0')*t[j]; } for (i=cb+cx-1;i>=0;i--) { if (s[i]>=10) { s[i-1]+=s[i]/10; s[i]%=10; } } i=0; while (s[i]==0) { i++; } k++; for (j=0;i<cx+cb;i++,j++) { b[k][j]=s[i]+'0'; } b[k][j]='\0'; } int main() { int n,i; strcpy(b[2],"2"); for(i=3;i<101;i++) { js(i); } while (cin>>n) { if (n==0) cout<<1<<endl; else if (n==1||n==2) cout<<n<<endl; else { cout<<b[n]<<endl; } } }