#include<iostream.h>
int fan(int n)
{int sum1=1;
for(int i=1;i<=n;i++)
sum1=sum1*i;
return sum1;
}
void main()
{
int c; int sum=0;
cout<<"请输入要想加的阶乘数字:"<<endl;
cout<<"输入0结束."<<endl;
for(int i=0;;i++)
{cin>>c;
if(c==0)break;
else
sum=sum+fan(c);
}
cout<<sum;
}