Pagini recente » Cod sursa (job #2610012) | Cod sursa (job #2147992) | Autentificare | Cod sursa (job #2967940) | Cod sursa (job #1803650)
#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 a = 0,b = 100000000,x,y;
if(p == 0)
return 1;
while(a <= b)
{
x = (a + b)/ 2;
y = nrcifrezero(x);
if(p > y)
a = x;
if(p < y)
b = x;
if(p == y)
return x - x%5;
}
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);
}