Cod sursa(job #9033)

Utilizator hpetru_bzHlihor Petru hpetru_bz Data 26 ianuarie 2007 14:19:10
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<fstream.h>
int main()
   {
   ifstream fin("fact.in");
   ofstream fout("fact.out");
   int N,p,m,n,x,a;
   long int f,g,h;
   fin>>p;
   N=1;
   f=1;
   a=1;
   while(a!=0)
      {
      f=f*N;
      g=f;
      h=f;
      m=0;
      n=0;
      while(g%2==0)
	 {
	 m=m+1;
	 g=g/2;
	 }
      while(h%5==0)
	 {
	 n=n+1;
	 h=h/5;
	 }
      if(m>n)x=n;
      else x=m;
      if(x==p){
	      a=0;
	      N=N-1;
	      }
      if(x>p){
	     a=0;
	     N=-2;
	     }
      N=N+1;
      }
   fout<<N<<"\n";
return 0;
   }