Cod sursa(job #2038611)

Utilizator AlexandruPaulSirbu Alex AlexandruPaul Data 13 octombrie 2017 20:49:51
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int st,dr,x,p,n,m;
int main()
{
    fin>>p;
    if (p==0)
    {
        fout<<1;
        return 0;
    }
    st=1;
    dr=800000000;
    while (st<=dr && n!=p)
    {
        n=0;
        m=(st+dr)/2;
        x=m/5;
        while(x)
        {
            n+=x;
            x/=5;
        }
        if (n>p)
            dr=m-1;
        else
            st=m+1;
    }
    if (st<=dr)
        fout<<m-m%5;
    else
        fout<<-1;
    return 0;
}