Cod sursa(job #2986553)

Utilizator Sebi_RipaSebastian Ripa Sebi_Ripa Data 28 februarie 2023 19:16:08
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <iostream>
#include <fstream>
#define input "fact.in"
#define output "fact.out"
#define ull unsigned long long
using namespace std;

int p;

inline ull zeroCount (ull n)
{
    ull currentPower = 5;
    ull result = 0;
    while (n >= currentPower)
    {
        result += n/currentPower;
        currentPower*=5;
    }
    return result;
}

int main()
{

    ifstream f (input);
    ofstream g (output);
    f >> p;
    ull RIGHT = 10000000000;
    ull LEFT = 1;
    ull MID;

    while (LEFT < RIGHT)
    {
        MID = (LEFT+RIGHT)/2;
        if (zeroCount(MID) > p)
        {
            RIGHT = MID - 1;
        }
        else if (zeroCount(MID) < p)
        {
            LEFT = MID + 1;
        }
        else
        {

            break;
        }
    }
    ull zeroCNow=zeroCount(MID);
    while (zeroCount(MID) == zeroCNow && MID>=1)
        MID--;
    g<<MID+1;
    return 0;
}