Cod sursa(job #2038610)
Utilizator | Data | 13 octombrie 2017 20:48:59 | |
---|---|---|---|
Problema | Factorial | Scor | 95 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.55 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int st,dr,x,p,n,m;
int main()
{
fin>>p;
if (p==0)
fout<<1;
st=1;
dr=800000000;
while (st<=dr && n!=p)
{
n=0;
m=(st+dr)/2;
x=m/5;
while(x)
{
n+=x;
x/=5;
}
if (n>p)
dr=m-1;
else
st=m+1;
}
if (st<=dr)
fout<<m-m%5;
else
fout<<-1;
return 0;
}