Cod sursa(job #3365816)

Utilizator Diaconescu99Mihai Diaconescu Diaconescu99 Data 25 septembrie 2026 18:07:11
Problema Factorial Scor 95
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

long long zerouri(long long n)
{
    long long s=0;

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

    return s;
}

int main()
{
    long long P;
    fin >> P;

    long long st=1,dr=5*P,r=-1;

    while (st<=dr)
    {
        long long mij=(st + dr)/2;
        long long z=zerouri(mij);

        if (z>=P)
        {
            if (z==P)
                r=mij;

            dr=mij-1;
        }
        else
            st=mij+1;
    }

    fout<<r;

    return 0;
}