Cod sursa(job #2325537)
Utilizator | Data | 22 ianuarie 2019 18:44:52 | |
---|---|---|---|
Problema | Factorial | Scor | 95 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p,lo,hi,mi;
int nr5(int);
int main()
{
f>>p;
hi=5*p;
while(hi-lo>1)
{
mi=(lo+hi)/2;
if(nr5(mi)>=p)
hi=mi;
else
lo=mi;
}
if(nr5(hi)!=p)
g<<"-1";
else
g<<hi;
return 0;
}
int nr5(int x)
{
int ret=0;
while(x/5)
{
ret+=x/5;
x/=5;
}
return ret;
}