Cod sursa(job #2733606)

Utilizator As932Stanciu Andreea As932 Data 30 martie 2021 17:22:32
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

ll p;

ll cati_zero(ll nr)
{
    ll zeros=0;
    for(ll c = 5; c <= nr; c *= 5)
        zeros+=nr/c;

    return zeros;
}

int main()
{
    fin>>p;

    ll st=1,dr=50000000011 ,sol=-1;

        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            ll zero=cati_zero(mij);
            if(zero>=p)
            {
                sol=mij;
                dr=mij-1;
            }
            else
                st=mij+1;
        }

    fout<<sol;

    return 0;
}