Pagini recente » Cod sursa (job #357335) | Cod sursa (job #3122707) | Cod sursa (job #1125227) | Cod sursa (job #115446) | Cod sursa (job #429699)
Cod sursa(job #429699)
#include<stdio.h>
#include<values.h>
using namespace std;
long nr_zero (long k)
{
long sum=0;
long putere=5;
while (k/putere>0)
{
sum+=k/putere;
putere*=5;
}
return sum;
}
int main ()
{
long st,dr,p,m;
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
st=1; dr=5*p;
while (st<=dr)
{
m=(st+dr)/2;
if (nr_zero(m)>=p)
dr=m-1;
else st=m+1;
}
if (p==0) printf("1");
else
{
if (nr_zero(st)==p) printf("%d",st);
else printf("-1");
}
return 0;
}