Cod sursa(job #1430586)

Utilizator movo608Moldovan Andrei movo608 Data 8 mai 2015 17:24:45
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

long p, aux, v, answer;

int main() {
    fin >> p;
    if (p == 0) {
        fout << 1;
        return 0;
    }
    p *= 4;
    answer = 5 * (p / 5);
    while (true) {
        aux = answer;
        v = answer;
        while (aux > 0) {
            v -= aux % 5;
            aux /= 5;
        }
        if (v == p) {
            fout << answer;
            break;
        }
        if (v > p) {
            fout << -1;
            break;
        }
        answer += 5;
    }
    return 0;
}