Cod sursa(job #377947)
#include <iostream.h>
#include <math.h>
#include <fstream.h>
int factorial(unsigned long int n)
{
int i=0;
unsigned long int nr=0;
while(pow(5,i)<n)
i++;
for(int k=1;k<=i;k++)
nr+=n/pow(5,k);
return nr;
}
void binar(unsigned long int k,unsigned long int j,unsigned long int nr)
{
fstream g("fact.out",ios::out);
int ok=0;
unsigned long int cautat=0;
while(k<=j&&ok==0)
{
k++;
if(factorial(k)==nr&&ok==0)
{
ok=1;
cautat=k;
}
}
if(ok==0)
g<<-1;
else
g<<cautat;
}
int main()
{
unsigned long int nr,k,j;
fstream f("fact.in",ios::in);
fstream g("fact.out",ios::out);
f>>nr;
k=nr*4;
j=nr*5;
if(nr==0)
g<<0;
else
{
if(nr/5==(nr%5)-1)
g<<-1;
else
binar(k,j,nr);
}
return 0;
}