Cod sursa(job #2555293)

Utilizator As932Stanciu Andreea As932 Data 23 februarie 2020 21:03:36
Problema Factorial Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#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;

    for(ll i=5;i<=nr;i+=10)
    {
        ll cop=i;
        while(cop%5==0)
        {
            cop/=5;
            zeros++;
        }
    }

    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;
}