Cod sursa(job #1277438)
| Utilizator | Data | 27 noiembrie 2014 17:38:36 | |
|---|---|---|---|
| Problema | Factorial | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <cstdio>
using namespace std;
int zero(int x)
{
int s=0,a=5;
while(a<=x)
{
s+=x/a;
a*=5;
}
return s;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
int n=-1,p,st=0,dr=100000000,m,z;
scanf("%d",&p);
if(p==0)
printf("1");
else
{
while(st<=dr)
{
m=(st+dr)/2;
z=zero(m);
if(z>p)
dr=m-1;
if(z<p)
st=m+1;
if(z==p)
n=m,dr=m-1;
}
printf("%d\n",n);
}
return 0;
}
