Cod sursa(job #246980)

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

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

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

fcloseall();
return 0;
}