Cod sursa(job #2623162)

Utilizator paulconst1Constantinescu Paul paulconst1 Data 2 iunie 2020 18:07:55
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.69 kb
#include <iostream>
#include <fstream>

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

int n;
int NrZero(int n)
{
    int x=0;
    while(n>=5)
    {
        n/=5;
        x+=n;
    }
    return x;
}

int Cautare(int x, int y)
{
    int mij,aux;
    if(x>y)
        return 0;

    mij=(x+y)/2;
    aux=NrZero(mij);
    if(aux==n)
        return mij;

    if(aux>n)
        return Cautare(x, mij-1);

    return Cautare(mij+1, y);
}

int main()
{ int x;
    fin>>n;
    if(n==0)
        fout<<1;
    else
    {
        x=Cautare(0, n*5);
        x-=x%5;
        if(x==0)
            x-=1;
        fout<<x;
    }
    return 0;
}