Pagini recente » Cod sursa (job #1489852) | Cod sursa (job #573151) | Cod sursa (job #2500892) | Cod sursa (job #2831828) | 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;
}