Cod sursa(job #3148471)

Utilizator stefanchpStefan Chiper stefanchp Data 1 septembrie 2023 17:02:17
Problema Factorial Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;

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

int p;

int nrzero(int n)
{
	int sol = 0, p = 5;
	while (p <= n)
	{
		sol += n / p;
		p *= 5;
	}
	return sol;
}

int main()
{
	int sol = 0;
	fin >> p;
	int st = 1, dr = 100000000;
	while (st <= dr)
	{
		int mij = (st + dr) / 2;
		int aux = nrzero(mij);
		if (aux == p)
		{
			sol = mij;
			dr = mij - 1;
		}
		else if (aux > p)
			dr = mij - 1;
		else
			st = mij + 1;
	}
	if (sol == 0)
		fout << -1;
	else 
		fout << sol;
	return 0;
}