Cod sursa(job #2699422)

Utilizator TheGodFather2131Alexandru Miclea TheGodFather2131 Data 24 ianuarie 2021 14:05:27
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
//ALEXANDRU MICLEA

#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>
#include <chrono>
#include <assert.h>
#include <iostream>

using namespace std;
using ll = long long;

#define fast_cin() 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

//VARIABLES



//FUNCTIONS

ll zero(ll val) {

	ll tot = 0;
	ll m5 = 5;

	while (m5 <= val) {
		tot += (val / m5);
		m5 *= 5;
	}

	return tot;
}

//MAIN
int main() {

	#ifdef INFOARENA
		freopen("fact.in", "r", stdin);
		freopen("fact.out", "w", stdout);
	#endif

	fast_cin();

	

	ll p; cin >> p;
	if (p == 0) {
		cout << '1';
		return 0;
	}

	ll ans = -1;

	ll st = 1, dr = 10000000000;
	while (st <= dr) {
		ll mid = (st + dr) / 2;
		int val = zero(mid);

		if (val == p) ans = mid;

		if (val < p) st = mid + 1;
		else dr = mid - 1;
	}
	cout << ans << '\n';

	return 0;
}