Cod sursa(job #51596)

Utilizator mariaciPopa Marius Ionut mariaci Data 15 aprilie 2007 14:14:06
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include<fstream.h>
#define InFile "fact.in"
#define OutFile "fact.out"
int i,j;
long p;
int main()
{ ifstream f(InFile);
  f>>p;
  int e2,e5,ok=1;
  e2=e5=0;
  while(ok)
    { i++;
      j=i;
      if(j%2==0)
	while(j%2==0)
	  { j=j/2;
	    e2++;
	  }
      if(j%5==0)
	while(j%5==0)
	  { j=j/5;
	    e5++;
	  }
      if(e2==p && e5>=p || e2>=p && e5==p) ok=0;
    }
  ofstream g(OutFile);
  if(i>=32000 && p!=0) g<<-1;
  else if(p==0) g<<1;
  else g<<i;

  g.close();
  f.close();
  return 0;
}