Cod sursa(job #2212409)

Utilizator pasoi_stefanPasoi Stefan pasoi_stefan Data 13 iunie 2018 22:38:55
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include<fstream>
using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
long long N,st,dr,P,rez,m,mm;
int main()
{
    cin>>P;
    st=1; dr=P*5;
    while(st<=dr)
    {
        m=(st+dr)/2; mm=0;
        while(m) {m/=5; mm+=m;}
        m=(st+dr)/2;
        if(mm<P) st=m+1;
        else if(mm>=P)
        {
            dr=m-1;
            if(mm==P) rez=m;
        }
    }
    if(rez==0) cout<<-1;
    else cout<<rez;
}