Cod sursa(job #1888773)

Utilizator mesbotMeszaros Botond mesbot Data 22 februarie 2017 12:32:02
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>

unsigned long long int p, n, nup, ndown = 1;

bool fact(unsigned long long int num)
{
    n = 0;
    while(num != 0)
        {num/=5; n += num;}

    return (n >= p);
}

void search_min()
{
    if(ndown <= nup)
        if(!fact(ndown))
            if((nup + ndown)/2 < nup-1)
                ndown = (nup + ndown)/2, search_min();
            else
                ndown = nup;
}


int main()
{
    std::ifstream f("fact.in");
    std::ofstream g("fact.out");

    f>>p;

    if(p != 0)
        nup = p*5, search_min();

    while(fact(ndown-1))
            ndown--;

    g<<ndown;

    return 0;
}