Cod sursa(job #2351197)

Utilizator FrostfireMagirescu Tudor Frostfire Data 22 februarie 2019 08:23:21
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <iostream>
#define inf 2100000000

using namespace std;

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

long long n, st, dr, sol;

int main()
{
    f >> n;
    if(n == 0)
    {   g << 1 << '\n';
        return 0;
    }
    st = 1;
    dr = inf;
    while(st<dr)
    {
        long long mij = (st + dr) / 2;
        long long n0 = 0, p = 5;
        while(mij >= p)
        {
            n0 = n0 + mij/p;
            p*=5;
        }
        if(n0 == n)
        {
            mij-=mij%5;
            g << mij << '\n';
            return 0;
        }
        else if(n0 > n) dr = mij - 1;
        else st = mij + 1;
    }
    g << st-st%5 << '\n';
    return 0;
}