Cod sursa(job #1837631)

Utilizator botimooMiklos Botond botimoo Data 30 decembrie 2016 11:06:46
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int nr_pow(int n, int p){
	if (n / p == 0)
		return 0;
	else return n / p + nr_pow(n / p, p);
}

int solve(int p, int s, int e){
	if (s == e){
		if (nr_pow(s, 5) == p)
			return s;
		else return -1;
	}
	else{
		int mid = (s + e) / 2;
		if (nr_pow(mid, 5) >= p)
			return solve(p, s, mid);
		else return solve(p, mid+1, e);
	}
}

int main(){
	int p;
	in >> p;

	int s = solve(p, 0, p*5);
	if (s == 0)
		s++;

	cout << s << endl;
	out << s << endl;

	return 0;
}