Cod sursa(job #2388637)

Utilizator oogaboogauvuvwevwevwe onyetenyevwe ugwemubwem ossas oogabooga Data 26 martie 2019 11:45:08
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

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

const int MX = 100000001;

int64_t nrZero(int64_t nr)
{
    int64_t nr_zero = 0, imp = 5;
    while(imp <= nr)
    {
        nr_zero += nr / imp;
        imp *= 5;
    }
    return nr_zero;
}

int main()
{
    int nr_zero, rsp = -1;

    in>>nr_zero;

    if(nr_zero == 0)
    {
        out<<1;
        return 0;
    }

    int st = 1, dr = 5*MX;

    while(st <= dr)
    {
        int fact = (st + dr) / 2;
        int nr_zero_curr = nrZero(fact);

        if(nr_zero_curr == nr_zero)
        {
            rsp = fact;
            dr = fact - 1;
        }
        else if(nr_zero_curr < nr_zero)
        {
            st = fact + 1;
        }
        else
        {
            dr = fact - 1;
        }
    }

    out<<rsp;

    return 0;
}