Cod sursa(job #1803599)
| Utilizator | Data | 11 noiembrie 2016 17:01:01 | |
|---|---|---|---|
| Problema | Factorial | Scor | 5 |
| Compilator | c | Status | done |
| Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <stdio.h>
#include <stdlib.h>
FILE *in,*out;
int nrcifrezero(int a)
{
int nr = 0,t = -1;
nr = a/5;
while(a >= 5)
{
t ++;
a = a/5;
}
return nr + t;
}
int cauta(int p)
{
int a = 0,b = 1000000000,x,y;
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;
}
