Pagini recente » Cod sursa (job #35145) | Cod sursa (job #3212364) | Monitorul de evaluare | Cod sursa (job #1639503) | Cod sursa (job #1803652)
#include <stdio.h>
#include <stdlib.h>
FILE *in,*out;
int nrcifrezero(int a)
{
int nr = 0,t = -1;
if(a == 0)
return 0;
while(a > 0)
{
nr = nr + a/5;
a = a/5;
}
return nr;
}
int cauta(int p)
{
int rez=0,pas;
for(pas=1<<28;pas;pas>>=1)
if(nrcifrezero(rez+pas)<p)
rez+=pas;
if(nrcifrezero(rez+1)==p)
return rez+1;
return -1;
}
int main()
{
in = fopen("fact.in","r");
out = fopen("fact.out","w");
int p,a = 0,b = 1000000000,z,nr = 0,cx,y,x;
fscanf(in,"%d",&p);
fprintf(out,"%d",cauta(p));
/*if(p == 0)
fprintf(out,"1");
while(a <= b)
{
nr = 0;
x = (a + b)/ 2;
cx = x;
while(cx > 0)
{
nr = nr + cx/5;
cx = cx/5;
}
y = nr;
if(p > y)
a = x;
if(p < y)
b = x;
if(p == y)
{
fprintf(out,"%d",x - x%5);
return 0;
}
}
fprintf(out,"-1");*/
return 0;
fclose(in);
fclose(out);
}