Cod sursa(job #53528)

Utilizator me_andyAvramescu Andrei me_andy Data 22 aprilie 2007 14:08:49
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<fstream.h>
#include<math.h>
 ifstream f("fact.in");
 ofstream g("fact.out");
int main()
{
 long a,c=0,x,j,c1,i;
 f>>a;
 if(a<0 || a>100000000)
  g<<-1;
  else
  {

 if(a==0)
 g<<1;
 else
 {
 for(i=125;i<=500000000;i+=125)
 {
  x=i;
  c=c+28;
  c1=28;
	while(x%125==0)
	{
	 x=x/125;
	 c=c+3;
	 c1=c1+3;
	}
	while(x%5==0)
	{

	c++;
	x=x/5;
	c1++;
	}
	if(c>=a)
	break;
 }
 j=i;
 if(c>a)
 {
 c=c-c1;
  for(j=i-125+5;j<=i;j+=5)
  {
	x=j;
	while(x%5==0 && c<a && x!=0)
	{

	c++;
	x=x/5;
	}
	if(c==a)
	 break;
  }
 }
 g<<j;
	}
}
 f.close();
 g.close();
 return 0;
}