#include <iostream>
using namespace std;
int fact(int n)
{//calculeaza n!
int p=1;
for(int i=2;i<=n;i++)
p=p*i;
return p;
}
int main()
{
int n,a[10],s[11],t=0,sc=0;
cin>>n;
int k=0;
while(n) //transforma n in sir de cifre
{
a[++k]=n%10;
n=n/10;
}
n=k;
//calculeaza suma de (n-1)!*cifra pt fiecare cifra
for(int i=1;i<=n;i++)
sc=sc+fact(n-1)*a[i];
//aduna cifra cu cifra (si transport)
for(int i=1;i<=n;i++)
{
s[i]=(sc+t)%10;//retin cifra
t=(sc+t)/10;//retin transportul
}
if(t>0)// a ramas transport
{
n++;//il pun in fata
s[n]=t;
}
for(int i=n;i>=1;i--)//afisez invers numarul
cout<<s[i];
return 0;
}
|