Cod sursa(job #2231096)
| Utilizator | Data | 12 august 2018 22:33:25 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.7 kb |
#include <iostream>
#include <fstream>
#define in ifstream("fact.in")
#define out ofstream("fact.out")
using namespace std;
int main(){
int n = 0, p = 0, z = 0;
in >> p;
long long f;
if(p == 0){
out << 1 << endl;
return 0;
} else {
n = 4 * p;
n = n - n%5;
f = 5;
while(f <= n){
z = z + n / f;
f *= 5;
}
}
while(!(z >= p)){
if(z < p){
n += 5;
}
f = n;
while(f % 5 == 0){
++z;
f /= 5;
}
}
if(z == p){
out << n << endl;
} else {
out << -1 << endl;
}
}
