Cod sursa(job #397743)

Utilizator toniobFMI - Barbalau Antonio toniob Data 17 februarie 2010 13:34:49
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include <cstdio>

using namespace std;

int P;

int zero (int x) {
	int rez = 0;
	while (x) {
		rez += x / 5;
		x /= 5;
	}
	return rez;
}

int BS (int p) {
	int i, pas = 1 << 30;
	for (i = 0; pas; pas >>= 1) {
		if (zero(i + pas) < p) {
			i += pas;
		}
	}
	return i + 1;
}

int main () {
	freopen ("fact.in", "r", stdin);
	freopen ("fact.out", "w", stdout);
	
	scanf ("%d", &P);
	
	if (zero(BS(P)) == P) {
		printf ("%d", BS(P));
	}
	else {
		printf ("-1");
	}
	
	return 0;
}