Pagini recente » Cod sursa (job #1778225) | Cod sursa (job #285994) | Cod sursa (job #1345282) | Cod sursa (job #2576661) | Cod sursa (job #2624524)
#include <iostream>
#include <fstream>
using namespace std;
int getFives(int x) {
int div = 5, res = 0, aux;
do {
aux = x / div;
res += aux;
div *= 5;
} while (aux > 0);
return res;
}
int searchFives(int p, int min, int max) {
if (max - min == 5) return max;
int pivot = min + (max - min) / 2;
pivot -= pivot % 5;
int fives = getFives(pivot);
if (fives == p)
return pivot;
else if (fives < p)
return searchFives(p, pivot, max);
else
return searchFives(p, min, pivot);
}
int main() {
fstream f("fact.in", ios::in);
int p;
f >> p;
f.close();
f.open("fact.out", ios::out);
if (p == 0)
f << 1;
else
f << searchFives(p, 0, 5*p);
f.close();
return 0;
}