Cod sursa(job #3133043)

Utilizator Dragos__1_1Dragos Antohi Dragos__1_1 Data 24 mai 2023 23:39:05
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
ifstream f("factorial.in");
ofstream g("factorial.out");
long long p,i,j;
int nr0(int x)
{   int nr2=0,nr5=0;
    for (int i=5;i<=x;i+=5)
    {   int ci=i;
        while (ci%5==0){nr5++;ci/=5;}
    }
    return nr5;
}
int main()
{
    f>>p;
    long long st=0,dr=p*p,poz,mid;
    //cout<<dr<<endl;
    while (st<=dr)
    {   mid=(st+dr)/2;
        int x=nr0(mid);
        if(x>=p){dr=mid-1;poz=mid;}
        else st=mid+1;
        //cout<<mid<<' '<<x<<endl;
    }
    //cout<<endl<<poz;
    if (nr0(poz)==p)g<<poz<<'\n';
    else g<<-1<<'\n';
    return 0;
}