Cod sursa(job #2936367)

Utilizator AlexandruCorneaCornea Alexandru Mihai AlexandruCornea Data 8 noiembrie 2022 18:53:37
Problema Factorial Scor 35
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>

using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int zero(int n)
{
    int p,s;
    p=5;
    s=0;
    while(p<=n){
        s+=n/p;
        p*=5;}
        return s;
}
int main()
{
    long long x;
    fin>>x;
    int st=1,dr=5*x;
    if (x==0)
    {
        fout<<1;
        return 0;
    }
    while (st<=dr)
    {
        int mij=(st+dr)/2;
        int zmij=zero(mij);
        if (zmij==x)
        {
            fout<<mij;
            return 0;
        }
        if (zmij<x)
            st=mij+1;
            else
           dr=mij-1;
    }

    return 0;
}