Cod sursa(job #2149124)

Utilizator Alex_BubBuburuzan Alexandru Alex_Bub Data 2 martie 2018 12:29:30
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>

using namespace std;

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

int nrz(int k)
{
    int s = 0;
    while(k > 4) {
        k /= 5;
        s += k;
    }

    return s;
}

int caut(int k)
{
    int st, m, dr, ans;
    bool found = false;
    st = 4 * k;
    dr = 5 * k;
    while(st <= dr) {
        m = (st + dr) >> 1;
        int n = nrz(m);

        if(n == k)
            found = true;

        if(n >= k) {
            ans = m;
            dr = m - 1;
        }
        else st = m + 1;
    }

    return (found) ? ans : -1;
}

int main()
{
    int x, ans;

    fin  >> x;

    ans = (x) ? caut(x) : 1;
    fout << ans;

    return 0;
}