Cod sursa(job #793207)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 2 octombrie 2012 12:00:43
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include<fstream>
using namespace std;

long long n,p,u,m,nr,k;

int main()
{
	ifstream f("fact.in");
	ofstream g("fact.out");
	f >> n;
	p=1;u=1000000000;
	while (p<=u)
	{
		m=(p+u)/2;
		k=5;nr=0;
		while (m/k>0)
		{
			nr+=m/k;
			k*=5;
		}
		if (nr>=n)
			u=m-1;
		else p=m+1;
	}
	nr=0;k=5;
	while (p/k>0)
		{
			nr+=p/k;
			k*=5;
		}
	if (nr==n)
		g << p;
	else g << -1;
	return 0;
}