Cod sursa(job #2907384)

Utilizator agamanAlexandru Gaman agaman Data 30 mai 2022 00:27:01
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.92 kb
// Infoarena.cpp : This file contains the 'main' function. Program execution begins and ends there.
#include <iostream>
#include <fstream>
#include <math.h>

void main()
{
	//std::cout << "Executing..." << std::endl;

	std::ifstream in;
	in.open("fact.in");
	std::ofstream out;
	out.open("fact.out");
	int target = 0;
	in >> target;
	in.close();

	if (target == 0 || target < 0) {
		out << -1;
		out.close();
		exit(0);
	}

	int n5 = 0;
	int n10 = 0;
	int index = 5;
	do {
		if (n10 + n5 > target) {
			out << -1;
			out.close();
			exit(0);
		}

		int current = index;
		double l10 = log10(current);
		if (l10 == floor(l10)) {
			n10 += l10;
			current = l10;
		}

		double log5 = log2(current) / log2(5);
		if (log5 == floor(log5)) {
			n5 += log5;
		}
		else if (current % 5 == 0) {
			n5 += 1;
		}

		index += 5;
	} while (n10 + n5 != target);

	out << index - 5;
	out.close();
	exit(0);
}