Cod sursa(job #324656)

Utilizator veleanduAlex Velea veleandu Data 16 iunie 2009 17:05:41
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 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;

	}
	if(zero(first)==p)
		out<<first;
	else
		out<<"-1";


	return 0;
}