Cod sursa(job #2628387)

Utilizator etohirseCristi Cretu etohirse Data 15 iunie 2020 18:32:28
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
using namespace std;

#define ll long long 
#define fisier 1

int32_t main(){
	#ifdef fisier
        ifstream cin("fact.in");
        ofstream cout("fact.out");
    #endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin >> n;
	if (n == 0){
		cout << 1;
		return 0;
	}
	ll st = 1, dr = 1e9, sol = -1, mid, x;
	while (st <= dr){
		mid = st + (dr - st) / 2;
		x = 0;
		for (ll i = 5; i <= mid; i*=5)
			x += (mid/i);
		if (x == n){
			sol = mid;
			dr = mid - 1;
		}
		else if(x > n)
			dr = mid -1;
		else
			st = mid + 1;
	}
	cout << sol;
}