Cod sursa(job #2123703)
Utilizator | Data | 6 februarie 2018 15:47:21 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.44 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int calcul(int x)
{
int p,s;
p=5;
s=0;
while(p<=x)
{
s=s+x/p;
p=p*5;
}
return s;
}
long long p,st,dr,nr,mij;
int main()
{
f>>p;
st=1;
dr=5*p;
while(st<=dr)
{
mij=(st+dr)/2;
nr=calcul(mij);
if(nr<p)st=mij+1;
else dr=mij-1;
}
if(calcul(st)==p)g<<st;
else g<<"-1";
return 0;
}