Cod sursa(job #2256031)

Utilizator emadinuDinu Ema emadinu Data 7 octombrie 2018 20:31:29
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>

using namespace std;

int main(){
    int n = 0, p = 0, z = 0;
    long long f;
    ifstream in("fact.in");
    ofstream out("fact.out");
    in >> p;

    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 = f * 5;
        }
    }

    while(z<p)
        n += 5;
    f = n;

    while(f % 5 == 0){
            ++z;
            f /= 5;
        }
    }

    if(z == p){
        out << n << endl;
    } else {
        out << -1 << endl;
    }

}