Cod sursa(job #2790714)

Utilizator MattiaMattia Iojica Mattia Data 29 octombrie 2021 13:28:30
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>
#define mod 9973
#define ull unsigned long long

using namespace std;

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

int nr_zerouri(int n)
{
    int nr = 0;

    while(n > 0)
    {
        n /= 5;
        nr += n;
    }

    return nr;
}

void solve(int n)
{
    int st = 1, dr = 1e9;
    bool ok = 0;

    while(st < dr)
    {
        int m = (st + dr) / 2;
        int c = nr_zerouri(m);

        if(c == n)
        {
            st = m;
            dr = 0;
            ok = 1;
        }
        else
            if(c < n)
                st = m + 1;
        else
            dr = m;
    }

    if(ok)
        g << st - st % 5;
    else
        g << -1;
}

int main()
{
    int n;
    f >> n;

    if(n == 0)
        g << 1;
    else
        solve(n);
}