Pagini recente » Cod sursa (job #2468488) | Cod sursa (job #2740891) | Cod sursa (job #1452689) | Cod sursa (job #1694479) | Cod sursa (job #397698)
Cod sursa(job #397698)
#include<stdio.h>
#include<math.h>
long int functie(long int n)
{
long int s=0;
long int i=1;
while(pow(5,i)<=n)
{
s=s+n/pow(5,i);
i++;
}
return s;
}
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
long int nr,n,m,in=1,sf=1000000000,gasit=0,x;
scanf("%ld",&nr);
for(n=in;n<=sf;n++)
{
m=(in+sf)/2;
if(functie(m)==nr)
{
printf("%ld\n",m-m%5);
gasit=1;
break;
}
else
{
if(functie(m)<nr)
{
in=m+1;
n=in;
}else
{
sf=m-1;
}
}
}
if(nr==1){
printf("5");
gasit=1;
}else{
if(nr==0){
printf("1");
gasit=1;
}
}
if(gasit==0)
{
printf("-1");
}
return 0;
}