Cod sursa(job #2699410)

Utilizator TheGodFather2131Alexandru Miclea TheGodFather2131 Data 24 ianuarie 2021 13:41:11
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.26 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

vector <int> m5;
const int maxn = 100000005;
int v[maxn];

//FUNCTIONS

int zero(int val) {
	// given val, return number of trailing zeroes for val!
	int tot = 0;
	int m5 = 5;

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

	return tot;
}

//MAIN
int main() {

	#ifdef INFOARENA
		freopen("", "r", stdin);
		freopen("", "w", stdout);
	#endif

	fast_cin();

	

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

	int ans = -1;

	int st = 1, dr = maxn;
	while (st <= dr) {
		int mid = (st + dr) / 2;

		if (zero(mid) == p && (mid % 5) == 0) ans = mid;
		if (zero(mid) < p) st = mid + 1;
		else dr = mid - 1;
	}
	cout << ans << '\n';

	return 0;
}