Pagini recente » Cod sursa (job #1671733) | Cod sursa (job #1978067) | Cod sursa (job #1476020) | Cod sursa (job #101545) | Cod sursa (job #2664569)
#include <stdio.h>
#include <stdlib.h>
#define N 100000000
int five_count(int n){
int put = 5, fives = 0;
while (put <= n){
fives += n / put;
put *= 5;
}
return fives;
}
int find (int n){
int min = 0, max = N, mij;
int fives;
while (max - min > 1){
mij = (max + min) / 2;
fives = five_count(mij);
if (n < fives){
max = mij - 1;
}else if (n > fives){
min = mij + 1;
}else{
min = mij;
max = 0;
}
}
if (n == five_count(min) || n == five_count(max)) return min;
else return -1;
}
int main()
{
FILE *fin, *fout;
fin = fopen("fact.in", "r");
fout = fopen("fact.out", "w");
int n;
fscanf(fin, "%d", &n);
if (n == 0){
fprintf(fout, "1");
}else{
int x = find(n);
if (x == -1) fprintf(fout, "%d", x);
else {
x = x - (x % 5);
fprintf(fout, "%d", x);
}
}
return 0;
}