Cod sursa(job #2245815)

Utilizator ZydanCostica Dan Zydan Data 25 septembrie 2018 22:03:56
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.42 kb
#include <fstream>
using namespace std;


int nrzero(const int& p)
{

	int x = 5;
	int y = 0;
	while (p / x > 0)
	{
		y += p / x;
		x *= 5;
	}
	return y;
}


int main()
{
	ifstream in("fact.in");
	ofstream out("fact.out");
	int p;
	in >> p;
	int x = 5;
	if(p == 0) out<<1;
	while (true)
	{
		if (nrzero(x) < p) x++;
		else break;
	}
	if (nrzero(x) == p) out << x;
	else out << -1;
	return 0;
}