Cod sursa(job #2056629)

Utilizator TC14Damsa Ioan Dinu TC14 Data 4 noiembrie 2017 12:33:24
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>

using namespace std;

ifstream f ("fact.in");
ofstream g ("fact.out");

int nr_0 (int x)
{
    int s=0;
    long long p=5;
    while (p<=x)
    {
        s=s+x/p;
        p=p*5;
    }
    return s;
}


int main()
{
    int p,st=5,dr=2000000000,x,ok=0,mij;
    f>>p;
    if (p==0)
    {
        g<<1;
        return 0;
    }
    while (st<=dr && ok==0)
    {
        mij=(st+dr)/2;
        x=nr_0(mij);
        if (x==p)
            ok=1;
        else
            if (x<p)
                st=mij+1;
            else
                dr=mij-1;
    }
    if (ok==1)
    {
        int aux=mij/5;
        g<<aux*5;
    }
    if (ok==0)
        g<<-1;
    f.close();
    return 0;
}