Cod sursa(job #751984)

Utilizator lucian666Vasilut Lucian lucian666 Data 27 mai 2012 16:30:40
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb


#include<fstream>

using namespace std;
ofstream out("fact.out");

int p;

int numar(int);

int main()
{

	ifstream in("fact.in");
	in>>p;
	int mid,st=1,dr=5*p;
	while(st<=dr)
	{
		mid=(st+dr)/2;
			if(numar(mid)>=p)
				dr=mid-1;
			else
				st=mid+1;
	}
	if(numar(st)==p)
		out<<st<<" ";
	else
		out<<-1;
	return 0;
}

int numar(int x)
{
	int nrc=0,pp=5;
	while(pp<=x)
	{
		nrc+=x/pp;
		pp*=5;
	}
	
	return nrc;
}