Cod sursa(job #1615405)
Utilizator | Oprea Bianca bioprea | Data | 26 februarie 2016 15:52:30 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.72 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
long a,b,c,d,s,p,d1;
fin>>p;
if(p==0)
fout<<1;
else
{a=1;b=200000000000000;
int ok=0;
while((a<=b)&&(!ok))
{
c=(a+b)/2;
s=0;d=c;
while(d)
{
s+=d/5;
d=d/5;
}
if(s==p) ok=1;
else
if(s>p) b=c-1;
else a=c+1;
}
if(ok)
{
d1=c-1;
do{d=d1;
s=0;
while(d)
{
s+=d/5;
d=d/5;
}
d1--;
}
while(s==p) ;
fout<<d1+2;
}
else fout<<-1;
}
return 0;
}