Cod sursa(job #324651)

Utilizator veleanduAlex Velea veleandu Data 16 iunie 2009 17:03:17
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include<fstream.h>

int first, last, p, mid;

int zero(int x)//care 0 are x!
{
	int p5 = 5;
	int d = 0;
	while (x/p5 != 0) {
		d += (x/p5);
		p5*=5;
	}
	return d;


}
int main()
{
//	cout<<zero(25);
	ifstream in("fact.in");
	ofstream out("fact.out");
	in>>p;

	first = 1; last = 6*p;

	while (first<=last) {
		mid = first + (last-first)/2;
		if (zero(mid)>=p)
			last = mid - 1;
		else
			first = mid + 1;

	}

	out<<first;

	return 0;
}