Cod sursa(job #2799257)

Utilizator matei0000Neacsu Matei matei0000 Data 12 noiembrie 2021 18:35:29
Problema Factorial Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");

int n;
int fct(int x)
{
    return x/5+x/25+x/126+x/625+x/3125+x/15625+x/78125+x/390625+x/1953125+x/9765625;
}
int cautbin2(int x)
{
    int st = 1;
    int dr = 100000000;
    int raspuns = -1;
    while(st <= dr)
    {
        int mij = (st + dr) / 2;
        if(fct(mij) >= x)
        {
            raspuns = mij;
            dr = mij - 1;
        }
        else
            st = mij + 1;
    }
    return raspuns;
}
int main()
{
    in >> n;
    out<<cautbin2(n);
}