Cod sursa(job #2959880)

Utilizator Luka77Anastase Luca George Luka77 Data 2 ianuarie 2023 23:10:12
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

/// INPUT / OUTPUT
ifstream fin("fact.in");
ofstream fout("fact.out");

/// GLOBAL VARIABLES
ll n, ans;

ll countzero(ll &num)
{
    ll div = 5;
    ll cnt = 0;
    while(num / div > 0)
    {
        cnt += num / div;
        div*=5;
    }
    return cnt;
}

/// SOLUTION
inline void solve()
{
    if(n == 0)
    {
        fout << 1;
        return;
    }
    int st = 1, dr = 1e9;
    while(st <= dr)
    {
        ll mid = (st + dr) / 2;
        ll c = mid;
        ll zero = countzero(mid);
        if(zero == n)
        {
            ans = c;
            dr--;
        }
        if(zero > n)
        {
            dr = mid - 1;
        }
        if(zero < n)
        {
            st = mid + 1;
        }
    }
    fout << ans;
}

/// READING THE INPUT
int main()
{
    ios::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);
    fin >> n;
    solve();
}