Cod sursa(job #2149624)

Utilizator stefii_predaStefania Preda stefii_preda Data 2 martie 2018 20:02:28
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>

using namespace std;

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

long long zero(int x)
{
    long long nr = 0;
    while(x > 0)
    {
        nr += x/5;
        x = x/5;
    }
    return nr;
}

int main()
{
    int p;
    in >> p;
    int inc = 1, sf = 1e9, mij;
    bool gasit = false;
    while(inc <= sf && gasit == false)
    {
        mij = (inc + sf)/2;
        if(zero(mij) > p)
            sf = mij - 1;
        else if(zero(mij) < p)
            inc = mij + 1;
        else gasit = true;
    }
    if(gasit == false)
        out << "-1";
    else
    {
        int k = mij;
        while( zero(k) == p)
            k--;
        out << k + 1;

    }


    return 0;
}