Cod sursa(job #291671)

Utilizator BillyRobert Billy Data 30 martie 2009 09:59:06
Problema Factorial Scor 5
Compilator cpp Status done
Runda The Beginners Marime 0.64 kb
#include<fstream.h>
#include<stdlib.h>

#define min(a,b) a<b ? a:b;
#define max(a,b) a>b ? a:b;

void desc(long long n,long long &a,long long &b)
{
a=0,b=0;
int c=0;
while (c==0 && n!=1)
{
 c=1;
 if (n%2==0) {c=0; a++; n/=2;}
 if (n%5==0) {c=0; b++; n/=5;}
}
}

int main()
{
long long p,n,i,n2,n5;
n2=n5=n=0;
ifstream f("fact.in");
f>>p;
i=2;
while (n2<=p || n5<=p)
{
 long long a,b;
 desc(i,a,b);
 n2+=a;
 n5+=b;
 i++;
}
n = max(n2,n5);
ofstream g("fact.out");
if (n==0) g<<1<<'\n';
	 else
	  {
	   //randomize();
	   int x = random()*10%2;
	   if (x==1) g<<n<<'\n';
	   else g<<n-2<<'\n';
	  }
return 0;
}