Cod sursa(job #2524300)

Utilizator pascu.dacian@gmail.comPascu Dacian [email protected] Data 15 ianuarie 2020 13:03:09
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.52 kb
#include <fstream>
#include <algorithm>
using namespace std;
int nr_zero(int n)
{
    int nr=0;
    while(n>=5)
    {
        nr+=(n/=5);

    }
    return nr;
}


ifstream fin("fact.in");
ofstream fout("fact.out");
long long p,st,dr,m;

int main(int argc,const char *argv[])
{
    fin>>p;
    st=1;
    dr=5e8;
    while(st<dr)
    {
        m=(st+dr)/2;

        if(nr_zero(m)>=p)
            dr=m;
        else if (nr_zero(m)<p)
            st=m+1;
    }
    if(nr_zero(st)==p)
    fout<<st;
    else
    fout<<-1;

    return 0;
}