Pagini recente » Cod sursa (job #1064492) | Cod sursa (job #3214420) | Cod sursa (job #2167534) | Cod sursa (job #174399) | Cod sursa (job #673673)
Cod sursa(job #673673)
#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<b-4)&&(dr>a+4))
{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;
else
st=y;
}
}
if(x!=P)
printf("-1");}
return 0;
}