Cod sursa(job #2555322)

Utilizator As932Stanciu Andreea As932 Data 23 februarie 2020 21:31:51
Problema Factorial Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>
#include <cmath>
#define ll long long
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

ll p;

ll cati_zero(int nr)
{
    ll zeros=nr/10;
    int powMax=(int)pow(nr,0.2);
    zeros+=zeros+(nr%5==0 && pow(5,powMax)!=nr)+powMax*(powMax-1)/2;

    return zeros;
}

int main()
{
    fin>>p;

    if(p==0)
        fout<<"1";
    else
    {
        ll st=2,dr=2000000000,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;
}