Pagini recente » Cod sursa (job #1222844) | Cod sursa (job #366051) | Cod sursa (job #2593117) | Cod sursa (job #343891) | Cod sursa (job #188529)
Cod sursa(job #188529)
#include <stdio.h>
int main(){
long long st = 0, dr = 500000000, 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;
}