Pagini recente » Cod sursa (job #591393) | Cod sursa (job #2879260) | Cod sursa (job #3215195) | Cod sursa (job #1141059) | Cod sursa (job #2605437)
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <time.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int makeMultiple(int x) {
int c = x % 10;
if (c >= 5)
c -= 5;
x -= c;
return x;
}
int no_of_zero(int x) {
int nr = 0;
for (int p = 5;p <= x;p *= 5) {
nr += x / p;
}
return nr;
}
int solve(int a, int b, int p) {
while (a <= b) {
int m = (a + b) / 2;
int nr = no_of_zero(m);
if (nr == p)
return makeMultiple(m);
if (nr < p)
a = m + 1;
else
b = m - 1;
}
return -1;
}
int main()
{
int p;
fin >> p;
if (p == 0)
fout << 1;
else
fout << solve(5, 5 * p, p);
return 0;
}