Cod sursa(job #2937315)

Utilizator DomnulMilandruMilandru Nicon-David DomnulMilandru Data 10 noiembrie 2022 10:36:30
Problema Factorial Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1 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 <fstream>

using namespace std;
ifstream cin("fact.in");
ofstream cout("fact.out");
long long fact(long long i)
{
    int suma=0,r=5;
    while(i/r)
    {
        suma=suma+i/r;
        r=r*5;
    }
    return suma;
}
int main()
{
    int st=1,dr=100000000;
    int p,poz;
    cin>>p;
    while(st<=dr)
    {
        int mij=st+(dr-st)/2;
        int r=fact(mij);
        if(r==p)
        {
            poz=mij;
            dr=mij-1;
        }
        else
           if(p<r)
           {
               dr=mij-1;
           }
           else
             st=mij+1;
    }
   cout<<poz;
    return 0;
}