Cod sursa(job #2280994)

Utilizator alexnigaNiga Alexandru alexniga Data 11 noiembrie 2018 15:04:25
Problema Factorial Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <iostream>
#include <fstream>

using namespace std;

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

const long long maxx = 100000000;

int check(long long mij, long long n)
{
    long long a = 5, s=0;

    while(mij / a > 0)
    {
        s = s + mij / a;
        a *= 5;
    }


    return s;

}

int nr=1;
void cautbinar(long long st, long long dr, long long n)
{
    if(st <= dr)
    {
        long long mij = (st + dr) / 2;

        int verf = check(mij, n);

        if (verf >= n && (check(mij - 1, n) < n))
        {
            g << mij;
            return;
        }
        if (verf >= n)
            cautbinar(st, mij - 1, n);
        else
            cautbinar(mij + 1, dr, n);
    }
}

int main()
{
    unsigned long long p;

    f >> p;

    if(p == 0)
        g << 1;
    else
        if(p == 1)
            g << 5;
        else
            cautbinar(1, maxx, p);

    return 0;
}