Pagini recente » Cod sursa (job #553060) | Cod sursa (job #2722649) | Cod sursa (job #972373) | Cod sursa (job #65657) | Cod sursa (job #2072086)
#include <fstream>
using namespace std;
int P;
int nrCifreZero(int x){
int rez, pow;
rez=0; pow=5;
while (pow<=x){
rez+=x/pow;
pow*=5;
}
return rez;
}
int main(){
int i, j, m;
ifstream fin ("fact.in");
fin >> P;
fin.close();
i=1; j=5*P;
while (i<=j){
m=(i+j)/2;
if (nrCifreZero(m)>=P)
j=m-1;
else
i=m+1;
}
ofstream fout ("fact.out");
if (P<0)
fout << "-1\n";
else if (P==0)
fout << "1\n";
else
fout << j+1 << '\n';
fout.close();
return 0;
}