Cod sursa(job #1442973)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 26 mai 2015 16:51:48
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <limits>
using namespace std;

const auto nr_zero = [](int n){
	int rez = 0;
	while(n){
		rez += n / 5;
		n /= 5; }
	return rez; };

template <typename Func>
int do_search(const int rez, Func f){
	if(rez == 0){
		return 1; }
	int st = 1, dr = numeric_limits<decltype(dr)>::max(), mij;
	while(st < dr){
		mij = st + (dr-st)/2;
		if(f(mij) >= rez){
			dr = mij; }
		else{
			st = mij+1; } }
	return f(st) == rez ? st : -1; }

int main(){
	ifstream f("fact.in");
	ofstream g("fact.out");
	int n;
	f >> n;
	g << do_search(n, nr_zero);
	return 0; }