Cod sursa(job #1515975)
| Utilizator | Data | 2 noiembrie 2015 16:01:00 | |
|---|---|---|---|
| Problema | Factorial | Scor | 95 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include<iostream>
#include<fstream>
#include<climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int zero(int m){
int p=5,k=0;
while(p<=m){
k=k+m/p;
p=p*5;
}
return k;
}
int main(){
int i,j,m,p;
bool ok;
fin>>p;
i=1;j=INT_MAX;ok=false;
while(i<=j&&!ok){
m=(i+j)/2;
if(zero(m)==p)ok=true;
else if(zero(m)<p)i=m+1;
else j=m-1;
}
if(ok){
m=m-m%5;
fout<<m<<" ";
}
else fout<<"-1";
return 0;
}
