Cod sursa(job #2659791)

Utilizator IRadu1529Radu Ionescu IRadu1529 Data 17 octombrie 2020 14:00:45
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
typedef long long ll;
ll n, mid, sol = 1e9, x, cond;

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 if(x == n){
				sol = min(sol, mid);
				cond = 1;
				r = mid - 1;
			}
		}
	}
}

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