Cod sursa(job #1238326)

Utilizator vladrochianVlad Rochian vladrochian Data 6 octombrie 2014 19:14:15
Problema Factorial Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <fstream>
using namespace std;

int N, sol, cnt;

ifstream fin("fact.in");
ofstream fout("fact.out");

bool Check(int val) {
	cnt = 0;
	for (int fact = 5; fact <= val; fact *= 5)
		cnt += val / fact;
	if (cnt < N)
		return true;
	return false;
}

int main() {
	fin >> N;
	for (int bit = 1 << 30; bit; bit >>= 1) {
		if (Check(sol | bit))
			sol |= bit;
	}
	if (cnt == N)
		fout << sol + 1 << "\n";
	else
		fout <<"-1\n";
	return 0;
}