Cod sursa(job #246977)

Utilizator Soimul_NegruIon Popescu Soimul_Negru Data 21 ianuarie 2009 22:32:50
Problema Factorial Scor 15
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[0]=0; ++v[1];}
     if(v[1]==5) {v[1]=0; ++v[2];}
      if(v[2]==5) {v[2]=0; ++v[3];}
       if(v[3]==5) {v[3]=0; ++v[4];}
	if(v[4]==5) {v[4]=0; ++v[5];}
	 if(v[5]==5) {v[5]=0; ++v[6];}
	  if(v[6]==5) {v[6]=0; ++v[7];}
	   if(v[7]==5) {v[7]=0; ++v[8];}
	    if(v[8]==5) {v[8]=0; ++v[9];}
	     if(v[9]==5) {v[9]=0; ++v[10];}
	      if(v[10]==5) {v[10]=0; ++v[11];}
	       if(v[11]==5) {v[11]=0; ++v[12];}}
    for(i=0;i<13;i++)
     {j=i;
      while(j)
       {v[i]=v[i]*5; j--;}
      x+=v[i];}
  if(x==p) cout<<n;
  else cout<<-1;}

fcloseall();
return 0;
}