Pagini recente » Cod sursa (job #2340276) | Cod sursa (job #231939) | Cod sursa (job #2621815) | Cod sursa (job #333594) | Cod sursa (job #673681)
Cod sursa(job #673681)
#include <stdio.h>
#include <math.h>
using namespace std;
long long P,x,i,y,j,z,st,dr,a,b;
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&P);
if(P==0)
printf("1");
else
{j=0;
i=1;
while(j==0)
{x=floor(pow(5,i));
z=0;
while(x>0)
{
x=x/5;
z=z+x;
}
if(P<z)
j=i;
else
i++;
}
st=floor(pow(5,j-1));
dr=floor(pow(5,j));
a=st;
b=dr;
while((x!=P)&&(st<=dr))
{y=(st+dr)/2;
z=y;
x=0;
while(z>0)
{
z=z/5;
x=x+z;
}
if(x==P)
{
y=y-y%5;
printf("%d",y);
}
else
{
if(x>P)
dr=y-1;
else
st=y+1;
}
}
if(x!=P)
printf("-1");}
return 0;
}