Pagini recente » Cod sursa (job #1516887) | Rating Leo Aslan (syphuongcuong3) | Cod sursa (job #718228) | Cod sursa (job #3210592) | Cod sursa (job #349594)
Cod sursa(job #349594)
#include<stdio.h>
int p,L,R,M,CL,CR,CM,c5(int u);
void read(),solve();
int main()
{
read();
solve();
return 0;
}
void read()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
}
void solve()
{
if(p==0){printf("1\n");return;}
L=1;CL=0;
R=500000000;CR=c5(R);
while(R-L-1)
{
M=(R+L)/2;
CM=c5(M);
if(CM>=p)
{
R=M;CR=CM;
}
else
{
L=M;CL=CM;
}
}
CR==p?printf("%d\n",R):printf("-1\n");
}
int c5(int u)
{
int ret=0;
while(u)
{
ret+=u/5;
u/=5;
}
return ret;
}