Cod sursa(job #2542393)

Utilizator CondoracheTudorCondorache Tudor CondoracheTudor Data 9 februarie 2020 21:28:39
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <iostream>
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");

int main()
{
     int n,m,p,nr,rez=-1,st,dr;
    in>>n;
    st=1;
    dr=1000000000;
    while(st<=dr)
    {
        m=(st+dr)/2;
        p=1;
        nr=0;
        while(p<=m)
        {
            p*=5;
            nr+=m/p;

        }
        if(nr<n)
            st=m+1;
        else
        if(nr>n)
            dr=m-1;
        else{
            rez=m;
            dr=m-1;
        }
    }
    out<<rez;
    return 0;
}