Cod sursa(job #2959885)

Utilizator Luka77Anastase Luca George Luka77 Data 2 ianuarie 2023 23:16:32
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 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 = -1;

ll countzero(ll num)
{
    int cnt = 0;
    while(num >= 5)
    {
        num /= 5;
        cnt+=num;
    }
    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 = mid - 1;
        }
        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();
}