Cod sursa(job #1268647)

Utilizator sherban26FMI Mateescu Serban-Corneliu sherban26 Data 21 noiembrie 2014 11:02:58
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long _div(long x)
{
    long d = 5, rez = 0;

    while (x / d)
    {
        rez += x / d;
        d *= 5;
    }

    return rez;
}

int main()
{
    long n, d, f = 5;

    fin >> n;

    if (n == 0)
        fout << 1;
    else
    {
        while (true)
        {
            d = _div(f);
            if (d == n)
            {
                fout << f;
                break;
            }

            f += 5 * (n - d);
        }
    }

    return 0;
}