Pagini recente » Cod sursa (job #2876182) | Cod sursa (job #379599) | Cod sursa (job #2377425) | Cod sursa (job #1205755) | Cod sursa (job #354765)
Cod sursa(job #354765)
#include<stdio.h>
int a[13];
int b[13];
int i,x, ok, ok2,p;
long n;
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
b[0]=1;
for (i=1; i<=12; i++)
b[i]=b[i-1]*5;
a[0]=0;
for (i=1; i<=12; i++)
a[i]=a[i-1]+b[i-1];
scanf("%ld",&p);
if (p==0)
{
ok2=0; printf("1\n");
}
else ok2=1;
n=0; ok=1;
while (p!=0 && ok)
for (i=1; i<=12; i++)
if ((a[i]<=p && a[i+1]>p) || (i==12 && a[i]<=p))
{
x=p/a[i];
if (x>4) ok=0;
n+=x*b[i];
p-=x*a[i];
break;
}
if (ok && ok2)
printf("%ld\n",n);
else
if (ok2)
printf("-1\n");
fclose(stdin); fclose(stdout);
return 0;
}