Cod sursa(job #1442970)

Utilizator tamionvTamio Vesa Nakajima tamionv Data 26 mai 2015 16:48:01
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 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){
	if(rez == 0){
		return 1; }
	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;
	const int rez = do_search(n);
	g << (count_cifre(rez) == n ? rez : -1);
	return 0; }