Pagini recente » Cod sursa (job #351316) | Cod sursa (job #578990) | Cod sursa (job #618027) | Cod sursa (job #850741) | Cod sursa (job #591759)
Cod sursa(job #591759)
#include<iostream.h>
#include<fstream.h>
#include<math.h>
fstream f("fact.in",ios::in), g("fact.out",ios::out);
long long contor,i,ok,ur=1,p,b,t;
int main()
{
long long k,v,pu=5,l,o,ok2=0;
f>>k;
if(k==0)
g<<i;
else
{while(contor<k && !ok)
{
i+=pu;
contor+=ur;
if(i==pu*5)
{ contor++;
ur=contor;
pu=pu*5;
}
if(contor>k)
ok=1;
}
p=pu/5;
l=ur;v=pu;b=(ur-1)/5;o=1;
while(ok && v<i && ok2==0)
{
v+=p;
l+=b;
if(l>k)
{ l-=b;v-=p;b=(b-1)/5;p=p/5;o=1;}
if(l==k)
ok=0;
}
if(ok2==1)
{ g<<"-1";cout<<"-1";}
else
{ g<<v;cout<<v;}
}
return 0;
}