Cod sursa(job #2131175)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 14 februarie 2018 14:36:52
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#define ll long long

using namespace std;

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

ll nrz(ll x)
{
    ll k = 0;
    while(x > 4) {
        x /= 5;
        k+=x;
    }
    return k;
}
int main()
{
    ll n;

    fin >> n;

    ll k;

    if(n == 0)
        fout << "1";
    else {
        bool ok = true;
        int i = n + n - nrz(5 * k);

        k = i;
        while(nrz(5 * k) != n) {
             k += (n - nrz(5 * k));

             if(i == k) {
                 ok = false;
                 break;
             }
        }

        fout <<((ok) ? 5 * k : -1);
    }

    return 0;
}