Cod sursa(job #247009)

Utilizator Soimul_NegruIon Popescu Soimul_Negru Data 21 ianuarie 2009 23:01:55
Problema Factorial Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream.h>
#include <stdio.h>
int main()
{int i;
long p,n=0,v[14],x=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+=5; ++v[0]; ++x;
    if(v[0]==5) {v[1]+=v[0]+1; v[0]=0; ++x;}
     if(v[1]==30) {v[2]+=v[1]+1; v[1]=0; ++x;}
      if(v[2]==155) {v[3]+=v[2]+1; v[2]=0; ++x;}
       if(v[3]==780) {v[4]+=v[3]+1; v[3]=0; ++x;}
	if(v[4]==3905) {v[5]+=v[4]+1; v[4]=0; ++x;}
	 if(v[5]==19530) {v[6]+=v[5]+1; v[5]=0; ++x;}
	  if(v[6]==97655) {v[7]+=v[6]+1; v[6]=0; ++x;}
	   if(v[7]==488280) {v[8]+=v[7]+1; v[7]=0; ++x;}
	    if(v[8]==2441405) {v[9]+=v[8]+1; v[8]=0; ++x;}
	     if(v[9]==12117030) {v[10]+=v[9]+1; v[9]=0; ++x;}
	      if(v[10]==60945155) {v[11]+=v[10]+1; v[10]=0; ++x;}
	       if(v[11]==305085780) {v[12]+=v[11]+1; v[11]=0; ++x;}
		if(v[12]==1525788905) {v[13]+=v[12]+1; v[12]=0; ++x;}}
  if(x==p) cout<<n;
  else cout<<-1;}

fcloseall();
return 0;
}