Cod sursa(job #283086)

Utilizator KolaStoica Tudor Kola Data 18 martie 2009 18:17:51
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<stdio.h>
long long int p,v[12],seg[12],tot;
int i,t,coef[12];
long long int pet(int a, int b) 
{long long int i=a; 
if(b==0)return 1;
b--;
while(b--)a*=i;
return a; 
}
int main(void)
{ 
freopen("fact.in","r",stdin); 
freopen("fact.out","w",stdout); 
for(i=0; i<12; i++)v[i]=pet(5,i);
for(i=0; i<12; i++)seg[i]=pet(5,i+1)/4;
scanf("%lld",&p); 
if(p==0) printf("%d",1);
  else { for(i=11; i>-1; i--) { coef[i]=p/seg[i]; 
                                p-=coef[i]*seg[i];
                               }
for(i=0; i<12; i++) if(coef[i]==5)t=1; 
if(t) printf("%d",-1);
  else { for(i=0; i<12; i++)tot+=coef[i]*v[i];
printf("%lld",5*tot); }
        } 
return 0; 
}