one_ZHI @ 2023-07-22 09:17:51
#include<bits/stdc++.h>
using namespace std;
int a[11111][11111],b[111111],lena[121111],lenb;
void gjc(int k,int n){
int x=0;
if(k>n) return;
for(int i=1;i<=lena[k-1];i++){
x=0;
a[i][k]+=k*a[i][k-1];
if(a[i][k]>=10){
x=a[i][k]/10;
a[i][k]%=10;
}
if(x!=0){
a[i+1][k]+=x;
}
}
if(a[lena[k-1]+1][k]>=10){
a[lena[k-1]+2][k]+=a[lena[k-1]+1][k]/10;
}
lena[k]=5000;
while(a[lena[k]][k]==0&&a[lena[k]+1][k]==0&&lena[k]>1) lena[k]--;
gjc(k+1,n);
return;
}
void gjj(int k,int n){
if(k>n) return;
a[1][0]=0;
for(int i=1;i<=lena[k];++i){
b[i]+=a[i][k];
if(b[i]>=10){
b[i+1]=b[i]/10;
b[i]%=10;
}
}
if(b[lena[k]]>=10){
b[lena[k]+1]=b[lena[k]]/10;
b[lena[k]]%=10;
}
gjj(k+1,n);
return;
}
int main(){
int n;
a[1][0]=1;
cin>>n;
lena[0]=1;
gjc(1,n);
gjj(1,n);
lenb=5000;
while(b[lenb]==0&&lenb>1) lenb--;
for(int i=lenb;i>=1;--i){
printf("%d",b[i]);
}
return 0;
}