Pagini recente » Cod sursa (job #1203458) | Cod sursa (job #1807026) | Cod sursa (job #1891886) | Cod sursa (job #965054) | Cod sursa (job #1604108)
#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)/5) / 2)*5;
int temp = parse(mid, 5, 0);
if (temp < pos)
l = mid + 5;
else if (temp == pos) break;
else
r = mid - 5;
}
return l;
}
int main()
{
int pos;
ifstream fin("fact.in");
fin >> pos;
fin.close();
int temp = bin(0, pos * 5, pos);
ofstream fout("fact.out");
if (pos == 0) fout << 1;
else
if (parse(temp, 5, 0) == pos)
fout << temp << endl;
else
fout << -1;
fout.close();
return 0;
}