Cod sursa(job #2659786)

Utilizator IRadu1529Radu Ionescu IRadu1529 Data 17 octombrie 2020 13:54:52
Problema Factorial Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
#define N 201
#define mod 98999
typedef long long ll;
ll n, mid, sol = 1e8, x, cond = 0;

ll evp(ll n) {
	ll pw = 5;
	ll cnt = 0;
	while (pw <= n) {
		cnt += n / pw;
		pw *= 5;
	}
	return cnt;
}

void find(ll l, ll r) {
	while (l <= r) {
		mid = (l + r) / 2;
		x = evp(mid);
		if (x > n)
			r = mid - 1;
		else {
			if (x < n)
				l = mid + 1;
			else {
				sol = min(sol, mid);
				cond = 1;
				r = mid - 1;
			}

		}

	}
}

int main() {
	fin >> n;
	find(1, sol);
	if (cond == 0)
		sol = -1;
	fout << sol;
}