Cod sursa(job #2286394)
| Utilizator | Data | 20 noiembrie 2018 10:29:01 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.71 kb |
#include <fstream>
#define LL long long
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
LL k,st,dr,mij,ok,prod,cmij,s,cif;
int main()
{
f>>cif;
if (cif==0)
g << -1;
else {
st=5;
dr=400000015;
while (st!=mij && dr!=mij) {
mij=(st+dr)/2+1;
prod=5;
cmij=mij;
s=0;
while (cmij/prod!=0) {
s+=cmij/prod;
prod*=5;
}
if (s==cif) {
ok=1;
break;
}
else if (s<cif)
st=mij;
else
dr=mij;
}
if (ok==1)
g<<mij/5*5;
else
g << -1;
}
return 0;
}
