Pagini recente » Cod sursa (job #1066216) | Cod sursa (job #2626155) | Cod sursa (job #716908) | Cod sursa (job #769179) | Cod sursa (job #1604121)
#include <iostream>
#include <fstream>
using namespace std;
int parse(int total, int divide, int ext)
{
int temp = total / divide;
if (temp != 0)
return parse(total, divide * 5, ext + temp);
else return ext;
}
int bin(int l, int r, int pos)
{
int mid;
while (l < r)
{
mid = (l + r) / 2;
int temp = parse(mid, 5, 0);
if (temp < pos)
l = mid + 1;
else
r = mid - 1;
}
return l;
}
int main()
{
long pos;
ifstream fin("fact.in");
ofstream fout("fact.out");
fin >> pos;
fin.close();
if (pos == 0) {
fout << 1;
}
else {
int temp = bin(1, pos * 5, pos);
if (parse(temp, 5, 0) == pos)
fout << temp << endl;
else
fout << -1;
}
fout.close();
fin >> pos;
return 0;
}