Cod sursa(job #2231095)
Utilizator | Data | 12 august 2018 22:32:33 | |
---|---|---|---|
Problema | Factorial | Scor | 95 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.68 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;
} 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;
}
}