Pagini recente » Cod sursa (job #1985977) | Cod sursa (job #1228368) | Cod sursa (job #2774148) | Cod sursa (job #837212) | Cod sursa (job #2592673)
#include <iostream>
#include <cstdio>
#define nmax 500000000
FILE * f = fopen("fact.in", "r");
FILE * g = fopen("fact.out", "w");
using namespace std;
int p;
int factorial (int h) {
int p = 1, h1, s = 0;
h1 = h;
while (p < h)
{
p = p * 5;
s = s + h1/p;
}
return s;
}
int main()
{ int ok = 0, q = 0, i;
fscanf(f,"%d",&p);
int st, dr, mid, wq;
st = 1;
dr = nmax;
if(p == 0)
fprintf(g,"1");
else
{
while (st < dr) {
mid = (st+dr)/2;
if (factorial(mid) < p)
st = mid + 1;
else
dr = mid;
}
if(factorial(st) == p)
fprintf(g,"%d",st - st%5);
else
fprintf(g,"-1");
}
fclose(f);
fclose(g);
return 0;
}