Cod sursa(job #1981649)

Utilizator brczBereczki Norbert Cristian brcz Data 16 mai 2017 12:42:48
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include<bits/stdc++.h>

#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define sz size
#define pb push_back
#define mp make_pair
#define bg begin
#define nd end
using namespace std;

#define int long long

const int maxn = 100003;
const int maxk = 1003;

ifstream fin("fact.in");
ofstream fout("fact.out");

int nrZero(int x){

	int ret =0 ;
	int n = 5;
	while(x >= n){
		ret+=x/5;
		n*=5;
	}
	return ret;
}


int32_t main(){

	// #ifndef ONLINE_JUDGE
	// freopen("input.in","r",stdin);
	// #endif

	ios_base::sync_with_stdio(false);

	int p;

	fin >> p;

	int lo = 0,hi = (int)(1e8);

	if(p == 0){
		fout << 1 << '\n';
		return 0;
	}

	while(lo < hi){

		int mid = (lo + hi) >> 1;
		if(nrZero(mid) >= p){
			hi = mid;
		}
		else{
			lo = mid + 1;
		}
	}
	fout << lo << '\n';

	return 0;
}