Pagini recente » Cod sursa (job #653285) | Cod sursa (job #2222877)
#include <iostream>
#include<fstream>
using namespace std;
ifstream f ("fact.in");
ofstream g ("fact.out");
int p,st,dr,mij,sol,gasit,cc;
int zerouri(int x)
{
int i,s=0;
for(i=5;x/i>=1;i=i*5)
{
s=s+x/i;
}
return s;
}
int main()
{f>>p;
st=1;
dr=5*p;
sol=0;
cc=0;
while(st<=dr)
{mij=(dr+st)/2;
gasit=zerouri(mij);
if(gasit==p){sol=mij;dr=mij-1;cc=1;}
else if (gasit<p){st=mij+1;}else dr=mij-1;}
if(cc==0)g<<-1;
else g<<sol;
return 0;
}