Cod sursa(job #2609116)

Utilizator PopeangaMihneaPopeanga Mihnea- Stefan PopeangaMihnea Data 2 mai 2020 10:53:56
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda igorj_mentorat1 Marime 0.63 kb
#include <iostream>
#include <fstream>

using namespace std;

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

typedef long long LL;

LL n, p, st, dr, m, r;

LL zero(LL x)
{
    LL nr=0;
    LL p=5;
    while(x>=p)
    {
        nr=nr+(x/p);
        p=p*5;
    }
    return nr;
}

int main()
{
    fin>>p;
    if(p==0) fout<<"1"<<"\n";
    else
    {
        st=1; dr=p*5+100;
        while(st<=dr)
        {
            m=(st+dr)/2;
            if(zero(m)>=p) dr=m-1;
            else st=m+1;
        }
        if(zero(st)==p) fout<<st<<"\n";
        else fout<<"-1"<<"\n";
    }
    return 0;
}