Cod sursa(job #2475447)

Utilizator Florinos123Gaina Florin Florinos123 Data 16 octombrie 2019 22:31:53
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <iostream>
#include <fstream>

using namespace std;
long verf(long n)
{
    long rez=0;
    while(n)
    {
        rez=rez+n/5;
        n=n/5;
    }
    return rez;
}
int main()
{
ifstream f("fact.in");
ofstream g("fact.out");
long long n,m,st=1,dr=999999999,gasit=0,nr;
f>>n;
if(n==0)
    g<<1;
else
{

while(st<=dr && gasit==0)
{
    m=(st+dr)/2;
    if(verf(m)==n)
      {
          gasit=1;
          nr=m;
      }
    else
    {
        if(verf(m)<n)
            st=m+1;
        else
           dr=m-1;
    }
}
if(gasit==0)
    g<<-1;
else
    {
        while(verf(nr)==n)
              nr--;
        nr++;
        g<<nr;
    }
}

    return 0;
}