Cod sursa(job #370526)
Utilizator | Data | 1 decembrie 2009 15:11:41 | |
---|---|---|---|
Problema | Factorial | Scor | 60 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.36 kb |
#include<fstream.h>
long m,a,p,r,l;
long fact(long x)
{
long b=5,e=0;
while(x>=b)
{
e+=x/b;
b*=5;
}
return e;
}
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
f>>p;
a=1;
while(fact(a)<p)a<<=1;
l=(a>>1)+1;r=a;
while(l<r)
{
m=l+((r-l)>>1);
if(fact(m)>=p)r=m-1;
else l=m+1;
}
g<<r;
return 0;
}