Cod sursa(job #444842)
| Utilizator | Data | 21 aprilie 2010 20:58:05 | |
|---|---|---|---|
| Problema | Factorial | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.4 kb |
#include<fstream.h>
int main ()
{
ifstream fcin("fact.in");
ofstream fcout("fact.out");
long long k,i=1,c[100001],u,p,j,i2,g,x;
fcin>>k;
c[i]=5;p=1;u=1;
x=0;i=5;g=25;
while(x<k)
{i2=i;
for(j=u;j>=p;j--)
if(i2%c[j]==0){x=x+j;i2=i2/c[j];break;}
i=i+5;
if(i==g){u++;c[u]=g;g=g*5;}}
if(x==k)if(k!=0)fcout<<i-5;
else fcout<<1;
else fcout<<-1;
return 0;
}