Pagini recente » Cod sursa (job #2701701) | Cod sursa (job #3271857) | Cod sursa (job #1109032) | Cod sursa (job #518759) | Cod sursa (job #673660)
Cod sursa(job #673660)
#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)
{
while(y%5!=0)
y--;
printf("%d",y);
}
else
{
if(x>P)
dr=y;
else
st=y;
}
}
if(x!=P)
printf("-1");}
return 0;
}