Cod sursa(job #900471)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 28 februarie 2013 19:48:42
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#define LL long long 
using namespace std;
const char iname[] = "fact.in";
const char oname[] = "fact.out";
ifstream fin(iname);
ofstream fout(oname);
int P, a, b, mid;
LL c;
inline LL pow_5(int x)
{
	LL s = 0;
	while (x)
	{
		s += (x / 5);
		x /= 5;
	}
	return s;
}
int main()
{
	fin >> P;
	a = 1; b = 500000000;
	while (1)
	{
		mid = (a + b) / 2;
		c = pow_5 (mid);
		if (c == P && a == b){ fout << b << '\n'; return 0; }
		if (a == b) { fout << -1 << '\n'; return 0; }
		if (P > c)
			a = mid + 1;
		if (P <= c)
			b = mid;
	}
	return 0;
}