Pagini recente » Cod sursa (job #1382112) | Cod sursa (job #1145306) | Cod sursa (job #2179512) | Cod sursa (job #616315) | Cod sursa (job #1411633)
#include<iostream>
#include<fstream>
using namespace std;
int p,n,nrzero,st,dr,poz,m;
int nrzfact(int x) {
int nr,pow;
nr=0;
pow=5;
while(x/pow>0){
nr=nr+x/pow;
pow*=5;
}
return nr;
}
int main(){
ifstream f("fact.in");
ofstream g("fact.out");
f>>p;
if (p==0) { g<<"1"; return 0; }
st=0;
dr=500000000;
poz=-1;
while (poz==-1 && st<=dr) {
m=(st+dr)/2;
nrzero=nrzfact(m);
//cout<<"m="<<m<<" nrzero="<<nrzero<<'\n';
if (nrzero==p) poz=m;
else if (p<nrzero) dr=m-5;
else st=m+5;
}
g<<poz/5*5<<'\n';
f.close();
g.close();
return 0;
}