Cod sursa(job #3174364)

Utilizator DesqucuDesq Stef Desqucu Data 24 noiembrie 2023 18:07:24
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int mij, st, dr, x, p;
int sol(int n)
{
    int p=1, cnt=0;
    while (p < n)
    {
        p *= 5;
        cnt += n / p;
    }
    return cnt;
}
int main()
{
    in >> p;
    st = 1;
    dr = 2147483646;
    x = -1;
    while (st <= dr)
    {
        mij = (st + dr) / 2;
        if (sol(mij) == p)
            x = mij;
        if (sol(mij) >= p)
            dr = mij - 1;
        else
            st = mij + 1;
    }
    out <<x;
}