Cod sursa(job #444840)
Utilizator | Data | 21 aprilie 2010 20:47:06 | |
---|---|---|---|
Problema | Factorial | Scor | 15 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.37 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--)
while(i2%c[j]==0){x=x+j;i2=i2/c[j];}
i=i+5;
if(i==g){u++;c[u]=g;g=g*5;}}
if(x==k)fcout<<i-5;
else fcout<<-1;
return 0;
}