Cod sursa(job #247114)

Utilizator Soimul_NegruIon Popescu Soimul_Negru Data 22 ianuarie 2009 09:56:43
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <iostream.h>
#include <stdio.h>
int main()
{int i,j;
long p,x=0,v[14],n=0;

freopen("fact.in", "r", stdin);
freopen("fact.out", "w", stdout);
cin>>p;

if(p==0) {cout<<1; return 0;}
else
 {for(i=0;i<14;i++) v[i]=0;
  while(x<p)
   {n+=25; v[2]+=25; x+=6; j=1;
    if(v[2]==125) {v[3]+=v[2]; v[2]=0; ++x; ++j;}
     if(v[3]==625) {v[4]+=v[3]; v[3]=0; ++x; ++j;}
      if(v[4]==3125) {v[5]+=v[4]; v[4]=0; ++x; ++j;}
       if(v[5]==15625) {v[6]+=v[5]; v[5]=0; ++x; ++j;}
	if(v[6]==78125) {v[7]+=v[6]; v[6]=0; ++x; ++j;}
	 if(v[7]==390625) {v[8]+=v[7]; v[7]=0; ++x; ++j;}
	  if(v[8]==1953125) {v[9]+=v[8]; v[8]=0; ++x; ++j;}
	   if(v[9]==9765625) {v[10]+=v[9]; v[9]=0; ++x; ++j;}
	    if(v[10]==48828125) {v[11]+=v[10]; v[10]=0; ++x; ++j;}
	     if(v[11]==244140625) {v[12]+=v[11]; v[11]=0; ++x; ++j;}}
  if(x==p) cout<<n;
  else if(x-p<=j) cout<<-1;
  else cout<<n-5*(x-p-j);}
fcloseall();
return 0;
}