Cod sursa(job #2534955)

Utilizator Vlad_AnicaAnica-Popa Vlad-Ioan Vlad_Anica Data 31 ianuarie 2020 10:49:23
Problema Factorial Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int zerouri(int x)
{
    int cnt=0;
    while(x>0)
    {
        cnt+=x/5;
        x/=5;
    }
    return cnt;
}

int main()
{
    long long  p,mijloc,dreapta,stanga;
    fin >> p;
    stanga=1;
    dreapta=100000001;
    if(p!=0)
    {
        while ( dreapta - stanga > 1 )
        {
          mijloc = (stanga + dreapta) / 2;
          if (zerouri(mijloc) >p)
            dreapta = mijloc;
          else
            stanga = mijloc;
        }
        while(zerouri(stanga)==p)
        stanga--;
        stanga++;
    }



    if(p==0)
        stanga=1;
   if(zerouri(stanga)==p)
        fout << stanga;
    else
            fout << -1;

    return 0;
}