Pagini recente » Cod sursa (job #3189671) | Cod sursa (job #2355651) | Cod sursa (job #2801051) | Cod sursa (job #1417093) | Cod sursa (job #2748541)
#include <fstream>
#include <cmath>
using namespace std;
int f(int x){
int p = 5, k = 0;
while(x / p > 0){
k = k + x / p;
p *= 5;
}
return k;
}
ifstream cin("factorial.in");
ofstream cout("factorial.out");
int main()
{
int p, k, x = 0;
cin >> p;
if(p == 0){
cout << 1;
}
else {
k = sqrt(p);
x = k;
while(f(x) < p){
x += k;
}
x -= k;
while(f(x) < p){
x ++;
}
if(f(x) > p){
cout << "-1";
}
else {
cout << x;
}
}
return 0;
}