Cod sursa(job #3141914)

Utilizator EricDimiC. Eric-Dimitrie EricDimi Data 17 iulie 2023 17:23:02
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <iostream>
#include <fstream>

using namespace std;

string nume = "aplicatie";

ifstream f(nume + ".in");
ofstream g(nume + ".out");

long long n, p = 0, cnt, x;

int main()
{
	f >> n;
	if (n == 0)
		p = 1;
	else
	{
		cnt = n;
		x = 5 * n;
		while (cnt >= n)
		{
			cnt = 0;
			p = 5;
			while (p <= x)
				cnt += (x / p), p *= 5;
			if (cnt == n)
			{
				g << x;
				return 0;
			}
			x -= 5;
		}
		g << -1;
	}

    return 0;
}