Pagini recente » Cod sursa (job #1921626) | Cod sursa (job #2135809) | Cod sursa (job #1086790) | Cod sursa (job #2720991) | Cod sursa (job #188530)
Cod sursa(job #188530)
#include <stdio.h>
int main(){
long long st = 0, dr = 1000000000, mijl, p, aux,nz;
FILE* in = fopen("fact.in", "r");
FILE*out = fopen("fact.out","w");
fscanf(in,"%lld",&p);
while (st<dr){
mijl = (st+dr)/2;
if (mijl%10 >= 5){
mijl /=10;
mijl = mijl * 10 +5;
}else{
mijl /=10;
mijl *=10;
}
if (aux == mijl) break;
else {
aux = mijl;
nz = 0;
while (aux){
nz+= aux/5;
aux/=5;
}
if (nz>p)
dr = mijl-1;
if (nz<p)
st = mijl + 1;
if (nz == p) break;
aux = mijl;
}
}
if (nz == p) fprintf(out, "%lld", mijl);
else fprintf(out, "-1");
return 0;
}