Cod sursa(job #2074354)

Utilizator cristianursacheCristian Ursache cristianursache Data 24 noiembrie 2017 15:20:16
Problema Factorial Scor 75
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 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, i = 0;
    while (pas != 0)
    {
        if (exp5 (r + pas) <= p)
            r += pas;
        pas /= 2;
    }
    if (exp5 (r + pas) != p)
        r = -1;
    else
        while (exp5 (r + pas) == p)
        {
            r --;
            i ++;
        }
    return r + 1;
}

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