Cod sursa(job #2845935)

Utilizator iuliacarpIulia Carp iuliacarp Data 8 februarie 2022 15:41:41
Problema Factorial Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int main ()
{
    int p;
    long long y;
    fin>>p;
    if(p==0) y=1;
    else
    {
        int n=0;
        int st=1,dr=1e8,mij,x=0;
        while(st<=dr&&n!=p)
        {
            n=0;
            mij=(st+dr)/2;
            x=mij/5;
            while(x>0)
            {
                n=n+x;
                x=x/5;
            }
            if(n>p) dr=mij-1;
            if(n<p) st=mij+1;
        }
        if(st<=dr) y=mij-mij%5;
        else y=-1;
    }
    fout<<y;
    return 0;
}