Cod sursa(job #2127434)
| Utilizator | Data | 10 februarie 2018 17:40:55 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p;
int zero(int x)
{
long long s=0;
while(x>=5)
{
s=s+x/5;
x=x/5;
}
return s;
}
int bsearch(int x)
{
long long st=0,m,dr=1000000000;
while(st<dr)
{
m=(st+dr)/2;
if(zero(m)>p)dr=m;
else st=m+1;
}
return st-5;
}
int main()
{
fin>>p;
if(p==0)fout<<1;
else if(zero(bsearch(p)) != p)
fout<<-1;
else fout<<bsearch(p);
}
