Cod sursa(job #94625)

Utilizator kojocojocaru aurelian kojo Data 24 octombrie 2007 10:15:48
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.39 kb
#include<fstream>
ifstream f("fact.in");
ofstream g("fact.out");
long long p,a=1,z=100000000000,e,az;
short ga;
long long suma(long long x)
{long long i,s=0;
for(i=5;i<=x;i*=5)
s+=x/i;
return s;
}
int main()
{
f>>p;
while(!ga&&a<=z)
	{az=(a+z)/2;
	 e=suma(az);
	 if(e<p)
		 z=az-1;
	 else
		 if(e>p)
			 a=az+1;
		 else
			 ga=1;
	}
if(ga)
	g<<az;
else
	g<<-1;
return 0;
}