Cod sursa(job #2609150)

Utilizator bogdanili123Iliescu Bogdan bogdanili123 Data 2 mai 2020 11:35:37
Problema Factorial Scor 30
Compilator cpp-64 Status done
Runda igorj_mentorat1 Marime 0.6 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f ("fact.in");
ofstream g ("fact.out");
int n, c ;
long long st, dr, m, x ;
int main()
{
    f>>n;
    st=1 ;
    dr=10000000;
    while(st<=dr)
    {
        m=(st+dr)/2 ;
        x=m;
        c=0;
        while(m!=0)
        {
            c=c+m/5 ;
            m=m/5;
        }
        if(c==n)
        {
            if(x-x%5==0) g<<"1";
            else g<<x-x%5 ;
            dr=-1 ;
        }
        else if(c>n) dr=(st+dr)/2-1 ;
        else st=(st+dr)/2+1 ;
    }
    if(dr!=-1) g<< "-1";
    return 0;
}