Mai intai trebuie sa te autentifici.
Cod sursa(job #1681072)
Utilizator | Data | 9 aprilie 2016 11:23:48 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
const int nmax=1e8;
int fct(int x) {
int y=x, sol=0;
while (y/5!=0) {
sol+=y/5;
y/=5;
}
return sol;
}
int main () {
int n;
fin>>n;
int n2;
for (n2=1; n2<=nmax*5; n2*=2) {
}
int sol=nmax*5;
for (int step=n2; step>0; step/=2) {
if (sol-step>=1 && fct(sol-step)>=n) {
sol-=step;
}
}
if (fct(sol)==n) {
fout<<sol<<"\n";
} else {
fout<<-1<<"\n";
}
return 0;
}