Cod sursa(job #834517)

Utilizator Theodor1000Cristea Theodor Stefan Theodor1000 Data 14 decembrie 2012 16:20:54
Problema Factorial Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#include <cstdio>

using namespace std;

int p, s, ci, i, x, cx, n, cp;
bool OK;

int main ()
{
	freopen ("fact.in", "r", stdin);
	freopen ("fact.out", "w", stdout);
	
	scanf ("%d", &p);
	cp = 5 * p + 1;
	n = 1;
	
	while (cp >= n)
	{
		x = (cp + n) / 2;
 		s = 0;
		
		for (cx = x; cx > 0;)
		{
			cx /= 5;
			s += cx;
		}
		
		if (s == p) break;
		else if (s < p) n = x + 1;
		else cp = x - 1;
	}
	
	if (!OK) printf ("%d\n", x);
	else printf ("-1\n");
	
	return 0;
}