Pagini recente » Cod sursa (job #235786) | Cod sursa (job #678487) | Cod sursa (job #1338843) | Cod sursa (job #1978053) | Cod sursa (job #562892)
Cod sursa(job #562892)
#include<stdio.h>
int p;
int nr0(int);
void bs(int,int);
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
bs(1,1000000000);
return 0;
}
void bs(int x,int y)
{
if(x>=y)
{
if(nr0(x)==p)
{
if(p==0)
printf("1");
else
printf("%d",x/5*5);
}
else
printf("-1");
}
else
{
if(nr0((x+y)/2)<p)
bs((x+y)/2+1,y);
else
bs(x,(x+y)/2);
}
}
int nr0(int z)
{
int s;
s=-z;
for(;z;z/=5)
s+=z;
return s;
}