Cod sursa(job #2100659)

Utilizator dragos.galeteanu2001Dragos Iulian dragos.galeteanu2001 Data 5 ianuarie 2018 23:32:34
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include <fstream>

using namespace std;

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

int zeroAid(int x)
{
	int nr = 0;
	while (x >= 5) nr += (x /= 5);
	return nr;
}

int main()
{
	long long int n, high = 0, INF = 1 << 30;
	in >> n;

	while (INF) {
		if (zeroAid(high + INF) < n) high += INF;
		INF >>= 1;
	}

	if (zeroAid(high + 1) == n) out << high + 1;
	else out << -1;

	in.close();
	out.close();
    return 0;
}