Cod sursa(job #2074366)

Utilizator cristianursacheCristian Ursache cristianursache Data 24 noiembrie 2017 15:26:51
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>

using namespace std;

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

int L = 27;

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;
    out << cautbin (p);
    return 0;
}