Cod sursa(job #2628374)

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

#define ll long long 
#define fisier 1

int32_t main(){
	#ifdef fisier
        ifstream cin("factorial.in");
        ofstream cout("factorial.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 = 1e8, sol = -1, mid, x;
	while (st <= dr){
		mid = st + (dr - st) / 2;
		x = 0;
		for (int 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;
}