Pagini recente » Cod sursa (job #2380114) | Cod sursa (job #32587) | Cod sursa (job #20549) | Cod sursa (job #1913064) | Cod sursa (job #1268626)
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int sol=-1,p;
int nrcif(long long x)
{
int k=0,j=5;
while(j<=x)
{
k=k+x/j;
j*=5;
}
return k;
}
void cautbin(long long st, long long dr)
{ int n;
long long m;
while (st<=dr)
{
m=(st+dr)/2;
n=nrcif(m);
if(n<p)
cautbin(m+1,dr);
else if(n>p)
cautbin(st, m-1);
else
{
sol=m;
cautbin(st,m-1);
}
}
}
int main()
{
f>>p;
long long st=1, dr=1000;
cautbin(st,dr);
g<<sol;
return 0;
}