Pagini recente » Profil mihnea_toader | Cod sursa (job #2137538) | Cod sursa (job #2188167) | Cod sursa (job #2968060) | Cod sursa (job #328351)
Cod sursa(job #328351)
#include<stdio.h>
long p;
void citeste();
long cauta(long,long);
long nrz(long);
int main()
{
freopen("fact.out","w",stdout);
long a,b,ok;
citeste();
if(!p)
printf("1");
else
if(p==1)
printf("0");
else
{
a=0;
b=1400000000;
ok=cauta(a,b);
if(ok==-1)
printf("-1");
else
printf("%ld",ok-ok%5);
}
return 0;
}
void citeste()
{
freopen("fact.in","r",stdin);
scanf("%d",&p);
}
long cauta(long x,long y)
{
long z;
if(x==y)
return -1;
else
{
z=nrz((x+y)/2);
if(z==p)
return ((x+y)/2);
else
{
if(z<p)
return cauta(x,((x+y)/2));
else
return cauta(((x+y)/2)+1,y);
}
}
}
long nrz(long nr)
{
long i,aux=0,bux;
for(i=5;i<=nr;i+=5)
{
bux=i;
while(bux%5==0)
{
aux++;
bux/=5;
}
if(aux>p)
break;
}
return aux;
}