Pagini recente » Cod sursa (job #2506717) | tema | Cod sursa (job #379267) | Cod sursa (job #583465) | Cod sursa (job #2460685)
#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 == 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 << findNum(numar) << '\n';
return 0;
}