Cod sursa(job #1268643)

Utilizator sherban26FMI Mateescu Serban-Corneliu sherban26 Data 21 noiembrie 2014 10:56:53
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 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;
            }

            if (d < n)
                f += 5;
            else
                f -= n - d;
        }
    }

    return 0;
}