Pagini recente » Cod sursa (job #1358625) | Cod sursa (job #164315) | Cod sursa (job #553162) | Cod sursa (job #2404291) | Cod sursa (job #1655517)
#include<stdlib.h>
#include<stdio.h>
int main(void) {
FILE *f, *g;
f = fopen("fact.in", "r");
g = fopen("fact.out", "w");
int nr0=0;
fscanf(f,"%d",&nr0);
if (nr0==0) {
fprintf(g,"%d\n",1);
return 0;
}
int min = 0;
int max = 100000000;
int fact = -1;
int mid = -1;
int cur_nr0 = -1;
int i = 0;
while(min <= max) {
cur_nr0=0;
mid = (min+max)/2;
for(i=5;i<=mid;i*=5) {
cur_nr0 += mid/i;
}
if (cur_nr0>nr0) max=mid-1;
else {
if(cur_nr0<nr0) min=mid+1;
else max=max-1;
}
}
if (cur_nr0==nr0) fprintf(g,"%d\n",mid);
else fprintf(g,"%d\n",-1);
return 0;
}