Cod sursa(job #805367)

Utilizator alecsandrualex cuturela alecsandru Data 31 octombrie 2012 12:13:12
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.33 kb
#include<stdio.h>
int p;

int zero(int n)
{
int r=0;
while(n>=5)
{r+=n/5;
n/=5;
}
return r;
}
int main()
{long long pas,i,j;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
pas=1<<30;
i=0;
while(pas!=0)
{if(zero(i+pas)<p)
i+=pas;
pas/=2;
}
j=i+1;
if(zero(j)==p)
printf("%d",j);
else
printf("-1");
return 0;
}