Cod sursa(job #2074377)

Utilizator cristianursacheCristian Ursache cristianursache Data 24 noiembrie 2017 15:33:50
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>

using namespace std;

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

int L = 29;

int p;

int exp5 (int x)
{
    int s = 0;
    while (x >= 5)
        s += (x /= 5);
    return s;
}

int cautbin (int x)
{
    int r = 0, pas = 1 << L;
    while (pas != 0)
    {
        if (exp5 (r + pas) < p)
            r += pas;
        pas /= 2;
    }
    //if (exp5 (r + pas + 1) != p)
        //r = -2;
    return r + 1;
}

int main()
{
    in >> p;
    if (p == 0)
        out << 1;
    int r = cautbin (p);
    if (exp5 (r) != p)
        r = -1;
    out << r;
    return 0;
}