Cod sursa(job #2493305)

Utilizator NeacsuMihaiNeacsu Mihai NeacsuMihai Data 16 noiembrie 2019 11:32:15
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <iostream>
#include <fstream>

using namespace std;

int zero (int x)
{
    if(x==0) return -1;
    else
    {
    int nr, p;

    nr=0;
    p=5;
    while(x/p!=0)
    {
        nr=nr+x/p;
        p=p*5;
    }

    return nr;
    }
}

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

    int n, p, u, mij, aux, aux2;
    bool ok;

    cin>>n;


    p=1;
    u=2000000;
    ok=0;

    while(p<=u && ok==0)
    {
        mij=(p+u)/2;
        aux=zero(mij);
        aux2=zero(mij-1);

        if(aux==n && aux2<n) ok=1;
        else if(aux<n) p=mij+1;
        else if(aux>n || aux2>=n) u=mij-1;
    }

    if(ok==1) cout<<mij;
    else cout<<-1;




}