Cod sursa(job #2069928)

Utilizator petru.ciocirlanPetru Ciocirlan petru.ciocirlan Data 18 noiembrie 2017 23:04:31
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int p, m, ch; // 400000015

int znumber(int x)
{
    int p5 = 5, nr = 0;
    while(p5 <= x)
    {
        nr += x/p5;
        p5 *= 5;
    }
    return nr;
}

void binfact(int st, int dr)
{
    if(st == dr)
        out << (znumber(st)==p? st:-1) << '\n';
    else
    {
        m = (st+dr)/2;
        if(znumber(m) < p)
            binfact(m+1, dr);
        else
            binfact(st, m);
    }
}

int main()
{
    in >> p;
    binfact(1, 400000016);
    in.close(), out.close();
    return 0;
}