Mai intai trebuie sa te autentifici.
Cod sursa(job #321776)
Utilizator | Data | 7 iunie 2009 12:07:38 | |
---|---|---|---|
Problema | Factorial | Scor | 95 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.56 kb |
#include<fstream.h>
#include<math.h>
long long p,mij,inc,sf,gasit,p2,t;
int main()
{
ifstream in("fact.in");
ofstream out("fact.out");
in>>p;
inc=5;
sf=5*p;
gasit=0;
while((gasit==0)&&(inc<=sf))
{ mij=(inc+sf)/2;
t=1;
p2=0;
while(t<=mij)
{t=t*5;
p2=p2+int(mij/t);
}
if(p2==p) gasit=1;
if(p2>p) sf=mij-1;
if(p2<p) inc=mij+1;
}
if(gasit==1) if(mij%5==0) out<<mij;
else {while(mij%5!=0)
mij=mij-1;
out<<mij;
}
else out<<"-1";
in.close();
out.close();
return 0;
}