Pagini recente » Cod sursa (job #325717) | Diferente pentru problema/pudge intre reviziile 15 si 16 | Cod sursa (job #2519223) | Cod sursa (job #2386988) | Cod sursa (job #2745087)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nrZerouriFact(int x)
{
int s = 0;
while (x > 0){
s += x / 5;
x /= 5;
}
return s;
}
int main()
{
int p, stanga, dreapta, sol;
fin >> p;
stanga = 1, dreapta = 1000000000;
while (stanga <= dreapta){
int mijloc = (stanga + dreapta) / 2;
if (nrZerouriFact(mijloc) >= p){
sol = mijloc;
dreapta = mijloc - 1;
}
else
stanga = mijloc + 1;
}
if (nrZerouriFact(sol) == p)
fout << sol;
else
fout << -1;
return 0;
}