Cod sursa(job #1442967)

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

int count_cifre(int n){
	int rez = 0;
	while(n){
		rez += n / 5;
		n /= 5; }
	return rez; }

constexpr int putere(const int baza, const int exp, const int rez = 1){
	return (exp == 0) ? rez : putere(baza*baza, exp/2, exp&1 ? baza*rez : rez); }

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

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