Pagini recente » Cod sursa (job #540691) | Cod sursa (job #2769105) | Cod sursa (job #417011) | Cod sursa (job #478471) | Cod sursa (job #2939333)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int check(int x) {
int t=5, cnt=0;
while(t<=x) {
cnt+=x/t;
t=t*5;
}
return cnt;
}
int main()
{
int p, n, cnt;
bool ok=false;
fin >> p;
if(p==0) {
fout << "1";
} else {
n=p*5;
while(ok==false) {
cnt=check(n);
//cout << "n=" << n << endl;
if(cnt>p) {
//cout << p << " " << cnt << endl;
if((cnt-p)/2>1 && check(n-5*((cnt-p)/2))>=p) {
n-=5*((cnt-p)/2);
} else {
n-=5;
}
} else if(p>cnt){
//cout << p << " " << cnt << endl;
fout << "-1";
break;
} else {
fout << n;
break;
}
}
}
return 0;
}