Cod sursa(job #2959879)

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

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

/// GLOBAL VARIABLES
int n, ans;

int countzero(int &num)
{
    int div = 5;
    int 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)
    {
        int mid = (st + dr) / 2;
        int c = mid;
        int 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();
}