Cod sursa(job #1997254)

Utilizator PopeangaMihneaPopeanga Mihnea- Stefan PopeangaMihnea Data 3 iulie 2017 19:56:33
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 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;
        r=-1;
        while(st<=dr)
        {
            m=(st+dr)/2;
            if(zero(m)>=p)
            {
                r=m;
                dr=m-1;
            }
            else st=m+1;
        }
        fout<<r<<"\n";
    }
    return 0;
}