Cod sursa(job #2505424)

Utilizator nicu_ducalNicu Ducal nicu_ducal Data 6 decembrie 2019 20:34:11
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <bits/stdc++.h>
#define MAX 1000000000
typedef unsigned int ui;
typedef long long ll;
using namespace std;

ll p;

ll zero(ll x)
{
    ll m = 5;
    ll put = 0;
    while (m <= x)
    {
        put = put + x / m;
        m *= 5;
    }
    return put;
}

ll bs(ll left, ll right)
{
    while (left <= right)
    {
        ll mid = left + (right - left) / 2;
        if (zero(mid) >= p)
        {
            right = mid - 1;
        }
        else if (zero(mid) < p)
        {
            left = mid + 1;
        }
    }
    return right + 1;
}

int main(){

ifstream cin("fact.in");
ofstream cout("fact.out");

cin >> p;

if (p == 0)
{
    cout << 1;
    return 0;
}

ll left = 5;
ll right = MAX;
cout << bs(left, right);

return 0;
}