Cod sursa(job #1861680)

Utilizator preda.andreiPreda Andrei preda.andrei Data 29 ianuarie 2017 10:51:27
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <fstream>

using namespace std;

const int kMaxVal = 1e8;

int FiveFactors(int x)
{
    int five_pow = 5;
    int factors = 0;

    while (five_pow <= x) {
        factors += x / five_pow;
        five_pow *= 5;
    }
    return factors;
}

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

    int n;
    fin >> n;

    int pow = (1 << 30);
    int pos = -1;

    while (pow > 0) {
        if (FiveFactors(pos + pow) < n) {
            pos += pow;
        }
        pow >>= 1;
    }

    fout << (FiveFactors(pos + 1) == n ? pos + 1 : -1) << "\n";
    return 0;
}