Cod sursa(job #688255)

Utilizator somfeleaniuliaSomfelean Iulia somfeleaniulia Data 23 februarie 2012 12:41:33
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<fstream>
using namespace std;

	fstream fin("fact.in",ios::in),fout("fact.out",ios::out);
	
int main()
{
	long long x,p,st,dr,mij,k;
	int ok=0;
	fin>>p;
	if(p==0)
	fout<<1;
	else
	{
		st=0;
		dr=p*5;
		while(st<=dr)
		{
			mij=(st+dr)/2;
			k=mij;
			x=0;
			while(k)
			{
				x=x+k/5;
				k/=5;
			}
			if(x==p)
			{
				ok=1;
			}
			if(x>=p)
				dr=mij-1;
			else
				st=mij+1;
		}
	
		if(ok==1)
		{
			if(mij%5!=0)
			{
				while(mij%5!=0)
					mij++;
			}
			fout<<mij;
		}
		else
			fout<<-1;
	}
	fin.close();
	fout.close();
	return 0;
}