Cod sursa(job #2618645)

Utilizator phayzeeeLeonard Vlaicu phayzeee Data 25 mai 2020 17:28:47
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
// Factorial.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <fstream>

bool check(long long p, long long num) {
	long long cpy = p, fact = 5, counter = 0;

	while (fact <= cpy) {
		counter += cpy / fact;
		fact *= 5;
	}

	if (counter >= num) {
		return true;
	}

	return false;
}

long long bin(long long num) {
	long long low = 0, high = num * 5;

	while (low < high) {
		long long mid = (low + high) >> 1;

		if (check(mid, num)) {
			high = mid;
		}

		else {
			low = mid + 1;
		}

	}

	return low;
}

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

int main() {
	long long p;
	in >> p;

	if (p == 0)
		out << 1;
	else
		out << bin(p);

	return 0;
}