Cod sursa(job #791776)

Utilizator tibi9876Marin Tiberiu tibi9876 Data 25 septembrie 2012 12:26:17
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.33 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;
	}
	g << p;
	return 0;
}