Cod sursa(job #2799253)

Utilizator matei0000Neacsu Matei matei0000 Data 12 noiembrie 2021 18:33:12
Problema Factorial Scor 10
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 cautbin1(int x)
{
    int st = 1;
    int dr = 1000000005;
    int raspuns = -1;
    while(st <= dr)
    {
        int mij = (st + dr) / 2;
        if(fct(mij) <= x)
        {
            raspuns = mij;
            st = mij + 1;
        }
        else
            dr = mij - 1;
    }
    return raspuns-4;
}
int main()
{
    in >> n;
    out<<cautbin1(n);
}