Pagini recente » Cod sursa (job #664474) | Cod sursa (job #766785) | Cod sursa (job #2555585) | Cod sursa (job #2229065) | Cod sursa (job #1837628)
#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)
solve(p, s, mid);
else 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;
}