Pagini recente » Cod sursa (job #2551243) | Cod sursa (job #747890) | Cod sursa (job #1180474) | Cod sursa (job #1667551) | Cod sursa (job #1736886)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
#define nmax 8100101
long long v[nmax];
long long i,x,p;
long long bs(long long s,long long d,long long x)
{
if(s>=d)
return s;
else
{
long long a=(s+d)/2;
if(v[a]==x)
return a;
if(v[a]>x)
return bs(s,a-1,x);
return bs(a+1,d,x);
}
}
int main()
{
for(i=1; i<nmax; ++i)
{
x=i;
v[i]=v[i-1]+1;
while(x-x/5*5==0)
{
x/=5;
++v[i];
}
}
f>>p;
x=bs(0,nmax-1,p);
if(v[x]==p)
g<<x*5;
else
g<<-1;
}