Cod sursa(job #1427872)

Utilizator GeiGeiGeorge Cioroiu GeiGei Data 3 mai 2015 10:32:59
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>

using namespace std;

int main() {
    ifstream fi("fact.in");
    ofstream fo("fact.out");

    long p;
    fi >> p;

    if (p == 0) {
        fo << 1;
        return 0;
    }
    p *= 4;
    long ans = 5 * (p / 5);

    while (true) {
        long aux = ans;
        long v = ans;
        while (aux > 0) {
            v -= aux % 5;
            aux /= 5;
        }
        if (v == p) {
            fo << ans;
            break;
        }
        if (v > p) {
            fo << -1;
            break;
        }

        ans += 5;
    }

    return 0;
}