Cod sursa(job #2299016)
Utilizator | Ionescu Tiberiu Tibi55 | Data | 8 decembrie 2018 19:12:31 |
---|---|---|---|
Problema | Factorial | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int nrz(int n)
{
int ex = 0, pp = 5;
while(n >= pp)
{
ex += n / pp;
pp *= 5;
}
return ex;
}
int cautbin(int a)
{
int p = 1, u = 100000000, poz = -1;
while(p <= u)
{
int m = p + (u - p) / 2;
int nz = nrz(m);
if(nz == a)
{
poz = m;
u = m - 1;
}
else
if(nz > a)
u = m - 1;
else
p = m + 1;
}
return poz;
}
int main()
{
int p;
f >> p;
g << cautbin(p);
return 0;
}