Pagini recente » Cod sursa (job #266228) | Cod sursa (job #2467763) | Cod sursa (job #963901) | Cod sursa (job #849493) | Cod sursa (job #2460691)
#include <fstream>
#include <cmath>
#include <iostream>
int countFactor(int p, int n) {
return (n < p ? 0 : (n / p + countFactor(p, n / p)));
}
int findNum(int n) {
if (n < 0) return -1;
if (n == 0) return 1;
if (n == 1) return 5;
int low = 0, high = 5*n, tmp = 0;
while (low <= high) {
int mid = low + (high - low) / 2;
if (countFactor(5, mid) < n) low = mid + 1;
else {
tmp = mid;
high = mid - 1;
}
}
return tmp;
}
int main()
{
std::ifstream in("fact.in");
std::ofstream out("fact.out");
int numar;
in >> numar;
out << (numar == 0 ? 1 : findNum(numar)) << '\n';
return 0;
}