Cod sursa(job #2788802)

Utilizator Andrei1105Andre Loga Andrei1105 Data 26 octombrie 2021 14:45:34
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nz(int n)
{
    int cnt=0;
    long long x=5;
    while(x<=n)
    {
        cnt+=n/x;
        x*=5;
    }
    return cnt;
}
int p,n;
int main()
{
    fin>>p;
    if(p==0)
        fout<<"1";
    else
    {
        int ok=0,poz=-1;
        int st=1;
        int dr=1000000000;
        while(st<=dr && ok==0)
        {
            int mij=(st+dr)/2;
            if(nz(mij)==p)
            {
                ok=1;
                poz=mij;
            }
            else if(nz(mij)<p)
                st=mij+1;
            else
                dr=mij-1;

        }
        if(ok==0)
            fout<<"-1";
        else
            fout<<poz-poz%5;
    }
    return 0;
}