Pagini recente » Cod sursa (job #125091) | Cod sursa (job #6066) | Cod sursa (job #282941) | Cod sursa (job #1709946) | Cod sursa (job #1803631)
#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 = 1000000000,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;
fscanf(in,"%d",&p);
z = cauta(p);
fprintf(out,"%d",z);
return 0;
fclose(in);
fclose(out);
}