Pagini recente » Cod sursa (job #332843) | Cod sursa (job #1206455) | Cod sursa (job #2610326) | Cod sursa (job #3158524) | Cod sursa (job #2379376)
#include <cstdio>
int nrDeZero(int x)
{
if (x<5) return 0;
return x/5+nrDeZero(x/5);
}
int main()
{
FILE *f = fopen("fact.in", "r");
FILE *fout = fopen("fact.out", "w");
int P=0, out=0, corect=0;
fscanf(f,"%d", &P);
if (P==0) {
fprintf(fout, "%d", 1);
return 0;
}
int high = P;
int low = 0;
while (low<=high)
{
int mid = low + (high-low)/2;
int x = nrDeZero(mid*5);
if (x==P) {
fprintf(fout, "%d", mid*5);
return 0;
} else if (x<P)
{
low = mid+1;
} else {
high = mid-1;
}
}
fprintf(fout, "%d", -1);
return 0;
}