Cod sursa(job #1482042)
Utilizator | Data | 5 septembrie 2015 21:22:27 | |
---|---|---|---|
Problema | Factorial | Scor | 80 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.45 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int n, p, e, x, y, ct;
int main(){
fin>>p;
x=5*p;
int k=5;
while(x>=k){
e+=x/k;
k*=5;
}
while(e>p){
y=x;
x-=5;
ct=0;
while(y%5==0){
ct++;
y/=5;
}
e-=ct;
}
if(e<p) fout<<-1;
else fout<<x;
return 0;
}